0

We have a "guest" form on our site, and a "guest" user to authenticate. Since the user has a set time zone, this is what (by default) is used by visualforce. Problem is, our Guest User will always be set to a time zone, regardless if our actual guest is in any other time zone. They may enter "2PM" in their datetime thinking their 2PM, wherever they may be, but it's really 2PM in the Guest User's time zone; unless the guest happens to be in the same time zone, none of these entries are correct.

Is there a way to detect the time zone of the device using our form, rather than the "guest" authenticated user?

1 Answer 1

3

Visualforce indeed does not have built-in support for this but you can use javascript to fetch the timezone from the browser.

Some suggested approaches are mentioned here: https://stackoverflow.com/questions/6939685/get-client-time-zone-from-browser

E.g. the following is a very simple approach:

In javascript (new Date()).getTimezoneOffset()/60 will return the current number of hours offset from UTC.

The time-zone offset is the difference, in minutes, between UTC and local time. Note that this means that the offset is positive if the local timezone is behind UTC and negative if it is ahead. For example, for time zone UTC+10:00 (Australian Eastern Standard Time, Vladivostok Time, Chamorro Standard Time), -600 will be returned.

2
  • 1
    Just make sure you worry about DST and DST transitions.
    – Phil W
    Jun 27, 2019 at 20:14
  • This is so appreciated - thank you! Jun 27, 2019 at 21:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .