Javascript provides us nice functions like toLocaleString, toLocaleTimeString etc. But I’m wondering – what is the right way to actually find out what the user’s locale is, or at least their current time zone?
The use case I have in mind is I’m asking the user to input a date and time, and I want to construct a Date object from that but I need to know what time zone to use, since there’s no standard function for it.
As far as I remember, the JavaScript doesn’t have any timezone information, it has only current timezone offset (which is changing during DST).
So, you could use
new Date(2011, 10, 16, 15, 2, 0, 0).getTime()to take current unix millseconds to determine precise instant of time using user’s current timezone. However, if you need then convert it between different timezones, you should ask user’s timezone explicitly and do conversions on server side.