3

Is there a way to determine the user’s web browser’s current default time zone from within a Vaadin 8.1 app?

Preferably get a ZoneId object rather than the legacy class TimeZone.

The WebBrowser class offers getter methods for getCurrentDate(), getDSTSavings(), getRawTimezoneOffset(), getTimezoneOffset(), and isDSTInEffect(). But none of those are a ZoneId. A mere offset is not a time zone. A time zone is a history of offset-from-UTC for a particular region, covering past, present, and future changes such as Daylight Saving Time (DST).

I am aware that ultimately the only reliable way to know the user’s desired/expected time zone is to explicitly ask them in my app. But it would be nice to have a guess as a default.


The proposed duplicate is not a duplicate, asking about getting the current date-time whereas my Question is about the time zone. Furthermore, my Question asks about the modern java.time classes while the proposed Question is about the flawed legacy date-time classes.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
  • @cfrick Nope, not a duplicate. I'm asking about *time zone*, not the *current time*. See my edits. – Basil Bourque Aug 29 '17 at 05:57
  • WebBrowser also holds the offsets. Currently there is no more (JS/Browser has no more to offer) – cfrick Aug 29 '17 at 06:01
  • @cfrick If you are confident of no other options, please make that an Answer for me to accept and close the Question. And kindly retract the incorrect duplicate proposal. – Basil Bourque Aug 29 '17 at 06:02

1 Answers1

1

An alternative for querying WebBrowser (or any other Vaadin API) is to use the client IP address and use a online service to get the geo information, including ZoneId.

See related Questions:

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
rmuller
  • 12,062
  • 4
  • 64
  • 92
  • Hmm, if you use the geo information *only* for this purpose, you are probably right, "a workaround". However, in many scenario's you will use the geo data in a broader context and then this approach might be better imho (separation of concerns) – rmuller Sep 06 '17 at 10:19
  • I suggest adding that to your Answer. – Basil Bourque Sep 06 '17 at 15:12