0

How do I find the Timezone offset of the users Browser in the Play Framework?

I believe I can do so with a little bit of Javascript like this:

var tzOffset = (new Date()).getTimezoneOffset()/60;

But getting the Javascript var from the Scala Template to the Controller's seems a bit of overkill. Plus it won't work for the index page.

Is there a better way?

Patrick McGloin
  • 2,204
  • 1
  • 14
  • 26

1 Answers1

1

First of all, not all offsets are full-hour ones. There are time offsets with 30 minute increments, even with 45 minutes after the full hour. Don't divide by 60.

Other than that, if you get a time from the Controller, you will get the one from the server, not the user. So, you are pretty much left with what you already have.

See also: Can You Determine Timezone from Request Variables?

Community
  • 1
  • 1
Aleksandar Stojadinovic
  • 4,851
  • 1
  • 34
  • 56