问题
For our Russia tenant we are using "Europe/Moscow" timezone. But we are getting time with 1 hour ahead of the correct time.
Europe/Moscow is UTC+3 hours. But when I am print date formated with Europe/Moscow timezone getting 1 hour ahead of the correct time.
Thanks, Syamala.
回答1:
I notice that there was a legislative change to Russian time zone definitions in October 2014; chances are that your JRE simply doesn't know about it yet.
The Java Timezone Updater Utility should be able to fix this for you. As time passes, the updated time zone definitions should also eventually get included by default in newer JREs (although that admittedly doesn't help you right now).
回答2:
you can use the joda-time api, version need greater than 2.5.because joda-time api update the timezone db after Russian time zone change 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:
Java 8:
System.out.println(LocalDateTime.now(ZoneId.of("Europe/Moscow"))
.format(DateTimeFormatter.ofPattern("d.MM.yyyy 'um' HH:mm 'Uhr'")));
回答4:
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"));
来源:https://stackoverflow.com/questions/26908043/getting-incorrect-time-leading-by-1-hour-with-europe-moscow-timezone