vertex 3.x fetch timezone from http request

I am using vertex 3.x. I have a requirement to access timezone from HttpServerRequest object to provide timezone based data to user.

Jon Skeet
people
quotationmark

It doesn't have one, basically. There's nothing in a regular HTTP request to identify the time zone.

Your options are:

  • Use an IP geocoding API to guess at the user's location, followed by a location-to-timezone conversion (e.g. through another API)
  • Use Javascript to detect the time zone - there are various libraries available to do this, usually resulting in an IANA time zone ID such as "Europe/London"
  • Probably in conjunction with the first two, offer the users a choice so they can confirm their actual time zone

Note that detecting location from IP address can be fraught with issues due to proxies which are often employed by large corporations.

Also note that even once you've got the same time zone ID as the browser, it's entirely possible that your copy of time zone data on the server will be different to the time zone data in the browser - it changes reasonably regularly. (You'd be fairly unlucky to hit a problem, so long as you keep your data up-to-date, but you should be aware of it.)

people

See more on this question at Stackoverflow