Pergunta

How can I parse a date string with Joda-Time datetime which uses the correct timezone WITH daylight saving time?

As an example in scala I try to parse the string "2014-04-07 01:00:00.000" (without timezone information). This date is coming from MySQL and is supposed to be in tz Europe/Berlin +01:00. What I like to have is a joda date time according to 2014-04-07 00:00:00+01:00 which is the timezone Europe/Berlin currently not on DST (GMT +1).

val fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS").withZone(DateTimeZone.forID("Europe/Berlin"))
val dt = fmt.parseDateTime("2014-04-07 01:00:00.000")

Unfortunately Joda-Time parses the date to 2014-04-07T01:00:00.000+02:00 which is currently the wrong offset (02:00 instead if 01:00)

Any ideas how to make Joda-Time parse the date with the correct DST offset?

Foi útil?

Solução

Joda-Time is correct. Your assumption of +01:00 for Berlin is incorrect. You did not account for Daylight Saving Time.

According to this page at TimeZoneConverter.com for the time zone "Europe/Berlin", Daylight Saving Time (DST) began on Sun 30-Mar-2014 at 02:00:00 A.M. when local clocks were set forward 1 hour. According to the Wikipedia list of time zone names, that means Berlin shifted from being one hour ahead of UTC (+01:00) to two hours ahead (+02:00).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top