Can I get the name of the time zone of the client by using jQuery?
No. jQuery has only one date/time function, which is $.now()
.
If you meant JavaScript, the answer is still no. You can only obtain a time zone offset from date.getTimezoneOffset()
. You can’t get a time zone – at least not in all browsers. Refer to the timezone tag wiki‘s section titled: "Time Zone != Offset"
You can guess at the time zone, by using the jsTimeZoneDetect library, but it is just a guess. It may or may not be accurate.
You can also now use moment.js with the moment-timezone add on. It now supports time zone guessing with moment.tz.guess()
.
If you can guarantee your users are running in an environment that fully supports the ECMAScript Internationalization API, you can get the user’s time zone like this:
Intl.DateTimeFormat().resolvedOptions().timeZone
You can review the compatibility table, under DateTimeFormat
– resolvedOptions().timezone defaults to the host environment
to determine which environments this will work in.
Honestly, the best thing to do is to just give your user a screen somewhere that they can select their timezone. You might use a drop-down list, or you might use a map-based timezone picker – like this one. You can use jsTimeZoneDetect as a default value, but your user should be able to change it.
Also, all of these are going to give you an IANA time zone identifier, such as America/Los_Angeles
. But the examples you gave appear to be Windows time zone ids (for use with TimeZoneInfo
in .net). You should read the timezone tag wiki, and then also this question: How to translate between Windows and IANA time zones?