Handling Time Zone differences when sending dates to javascript and reading back over AJAX
First convert to string:
string dateValue = lastRow.PublishDate.Value.ToLongDateString();
string timeValue = lastRow.PublishDate.Value.ToLongTimeString();
Pass to javascript like this:
String.Format("javascript:fnDoWork(new Date('{0} {1}'));",
dateValue,
timeValue)
When you read back:
DateTime lastDate = rawDate.ToLocalTime();
Now, what you sent is what you will get on the server.
Best way is to make sure all dates in the database are stored in UTC to avoid such complications.
string dateValue = lastRow.PublishDate.Value.ToLongDateString();
string timeValue = lastRow.PublishDate.Value.ToLongTimeString();
Pass to javascript like this:
String.Format("javascript:fnDoWork(new Date('{0} {1}'));",
dateValue,
timeValue)
When you read back:
DateTime lastDate = rawDate.ToLocalTime();
Now, what you sent is what you will get on the server.
Best way is to make sure all dates in the database are stored in UTC to avoid such complications.
Comments
Post a Comment