How To Handle Dst And Timezones In Javascript
What is the best approach for dealing with DST values when your web service accepts requests from different timezones than that of your server? My webservice accepts date strings
Solution 1:
You could also take a look at the XDate project for handling date objects in Javascript. It's quite similar to JodaTime (in Java). Very easy to use and semantic.
Solution 2:
Here's what I would do. Before you submit your data/time, parse the strings into a JavaScript Date
object. Then call getTime()
and submit that value. getTime()
returns the number of milliseconds since the UTC epoch, so in effect, it normalizes your times. Then when you return data to the user, pass in your UTC millisecond value to the constructor of a Date
object and display the time as you would. By default, it'll display in the user's timezone.
Post a Comment for "How To Handle Dst And Timezones In Javascript"