1

I have this line of code:

// I pass milliseconds timestamp on time var
ZonedDateTime zonedDatetIme = ZonedDateTime.ofInstant(java.time.Instant.ofEpochMilli(time), java.time.ZoneId.of("Asia/Almaty"))

When I try to output this time, it returns this:

System.our.println(zonedDatetIme)
// returns
2020-01-24T17:00+06:00[Asia/Almaty]

Then I'm trying to format this datetime:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern('dd.MM.yyyy hh:mm');
System.our.println(formatter.format(zonedDateTime));

Which returns to me this:

24.01.2020 05:00

That is wrong. It is like it substracting 6 hours of my timezone instead of adding it. Why this is happening?

Mr.D
  • 7,353
  • 13
  • 60
  • 119
  • 17-5=12 How did you get "It is like it substracting 6 hours of my timezone instead of adding it"? – Sweeper Jan 13 '20 at 13:35

1 Answers1

5

You are probably confusing h and H - h is the clock hour in the sense of AM/PM (in your example: 05:00 PM = 17:00) whilst H is the hour of the day.

Smutje
  • 17,733
  • 4
  • 24
  • 41