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.

Comments

Popular posts from this blog

Tutorial: Using Google Cloud Storage from C# and .NET

Late 2008 Macbook only giving 1.5 gb/s speed with 6 gb/s Intel SSD?

Enable Visual Studio to use more than 2GB of memory