Getting the wrong time leading to 1 hour, with the time zone Europe / Moscow

For our Russian tenant we use the time zone "Europe / Moscow". But we get time with 1 hour before the right time.

Europe / Moscow - UTC + 3 hours. But when I print the date formed with the Europe / Moscow time zone, getting an hour ahead of time.

Thanks, Syamala.

+7
java timezone
source share
4 answers

I notice that in October 2014 legislative changes were established to the definitions of Russian time zones; Most likely, your JRE just does not know about it.

The Java Time Zone Update Utility should be able to fix this for you. Over time, updated time zone definitions should also eventually be included by default in new JREs (although this admittedly does not help you right now).

+4
source share

you can use joda-time api, the version must be greater than 2.5. When joda-time api updates the db time zone after changing the Russian time zone from version 2.5.

Date timestamp = sdf.parse("11/17/2014 06:13:19"); TimeZone timezone = TimeZone.getTimeZone("Europe/Moscow"); DateTimeZone tz = DateTimeZone.forTimeZone(timezone); DateTime jodaDateTime = new DateTime(timestamp, tz); System.out.println(jodaDateTime.hourOfDay().get()); 
+3
source share

Java 8:

  System.out.println(LocalDateTime.now(ZoneId.of("Europe/Moscow")) .format(DateTimeFormatter.ofPattern("d.MM.yyyy 'um' HH:mm 'Uhr'"))); 
+1
source share

try threeteen

 import org.threeten.bp.format.* import org.threeten.bp.* DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String timestamp = dtf.format(ZonedDateTime.ofInstant(Instant.ofEpochMilli(MILLISECONDS_VALUE_HERE), ZoneId.of("Europe/Moscow")); 
0
source share

All Articles