Getting browser/client time zone offset for a specific date


I am trying the get the time zone offset of the browser/client for a specific date in the future. I know you can get the current time zone offset using the following :


But is it possible to get the time zone offset for a date in the future ? The reason I need this information is that I am trying to make sure that a specific time on any day will always be displayed as the same time no matter if you are in Daylight Saving Time or not.




Unless I’m missing something, here’s the best that you can do based on the current available information

int browserRawOffset = getBrowser().getRawTimezoneOffset();
String[] tzs = TimeZone.getAvailableIDs(browserRawOffset);

for (String tz : tzs) {
    boolean inDaylightTime = TimeZone.getTimeZone(tz).inDaylightTime(dateIWantToCheck);

so you’ll have a list of potential TimeZones the browser could be in, based on the raw offset, but if there’s more than one, could be that some of them are in DST and others are not.

You might get better results with a JavaScript snippet, perhaps using moment.js, but I’m not sure if all browsers are capable of giving accurate TZ information (more than what you get with RawTimezoneOffset).

Best regards,


Thank you for your answer.

That is exactly what I thought, it doesn’t seem to be posible using striclty Vaadin.

I have look into using Javascript with Vaadin but I am not familiar with it. I see you can use


But obviously I need the offset value in my Vaadin code. How would I go about returning a value from a javascript function to my Vaadin code ?

You can add JavaScript function callbacks in your Java code. See for more details on that.


Thank you, I managed to get something that works well. Javascript gives you the offset the opposite way that java does thought so you got to be careful about that. getBrowserTimeZoneOffset() gives me -240 while javascript date.getTimezoneOffset() gives me 240 for today in Eastern Standard Time.

        final int currentOffset = TimeZoneUtils.getBrowserTimeZoneOffset();

        JavaScript.getCurrent().addFunction("fixTimeZoneOffsetForDate", new JavaScriptFunction() {

          public void call(JsonArray arguments) {
            int specificDateOffset = -1 * (int) arguments.getNumber(0);

            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.MINUTE, specificDateOffset - currentOffset);


            "var date = new Date(" + value.getTime()
                + "); fixTimeZoneOffsetForDate(date.getTimezoneOffset());");

That’s a neat solution, I was expecting it to be more complicated :slight_smile: