In the UK, I would like to get the current offset from UTC / GMT. Currently, the offset is 1 hour, but there seems to be no way to find this.
the code
TimeZone timeZone = TimeZone.getDefault(); logger.debug("Timezone ID is '" + timeZone.getID() + "'"); if (timeZone.getID().equals("GMT")) { timeZone = TimeZone.getTimeZone("Europe/London"); logger.debug("New timezone is '" + timeZone.getID() + "'"); } Long eventDateMillis = Long.parseLong(eventDateValue.getKeyValue()); int timezoneOffset = timeZone.getOffset(eventDateMillis); logger.debug("Offset for " + eventDateValue + "(" + eventDateMillis + ") using timezone " + timeZone.getDisplayName() + " is " + timezoneOffset);
returns debug output
Wed 2012/09/19 16:38:19.503|Debug|DataManagement|Timezone ID is 'GMT' Wed 2012/09/19 16:38:19.503|Debug|DataManagement|New timezone is 'GMT' Wed 2012/09/19 16:38:19.557|Debug|DataManagement|Offset for 18 Sep 2012 09:00(1347958800000) using timezone Greenwich Mean Time is 0
In other words, the GMT time zone returns a zero offset, and I cannot find how to set it to return the correct offset.
If someone can provide a sample working code for JodaTime, it will do it, but I would really like it to not be necessary to install a separate library just for what should be single-line.
Java version is 7.
source share