I have a ASP.NET WEB.API 4 and a Controller returning the following json:
{ date: "2013-03-14T00:00:00" }
I parse it on the client (JavaScript):
date = new Date(json.date); // json.date being "2013-03-14T00:00:00"
Later I do a POST and in the body the date has changed format to
{ date: "2013-03-13T23:00:00.000Z" }
My guess was that some time zone stuff has been added by JavaScript or the browser?
Because of DB storing dates as int (yyyymmdd) I do the following convertion:
public static int ToInt(DateTime date)
{
return date.Year * 10000 + date.Month * 100 + date.Day;
}
The resulting int is then one day off :(
However if I do
date.ToLocalTime()
before calling the ToInt method, it looks fine.
Have I understood this correctly and is ToLocalTime() a sufficient solution or do I need to spend a day reading up on UTC dates in .NET and JavaScript?
Thanks!
int (yyyymmdd)??? What database do you use?