0

My local server is running in the eastern timezone and I would like to save the date a user enters in UTC. So I have a method that does the conversion

 public static Date getDate(LocalDateTime date, int timeZoneOffset) {
     OffsetDateTime dt = date.atOffset(ZoneOffset.ofTotalSeconds(timeZoneOffset));
     System.out.println(dt);
     Instant instant = dt.atZoneSameInstant(ZoneId.of(ZoneOffset.UTC.toString())).toInstant();
     System.out.println(instant);
     Date d = new Date(instant.toEpochMilli());
     System.out.println(d);
     return d;
}

But the print out is this now:

2015-09-21T21:55-04:00 <- this is correct. input time with timezone offset EST

2015-09-22T01:55:00Z <- this is correct. input time in UTC

Mon Sep 21 21:55:00 EDT 2015 <- this is wrong cause it now reverted my UTC time back to EST/EDT time

Why is that? And how can I get the java.util.Date object from the UTC time?

Thanks Chris

Community
  • 1
  • 1

0 Answers0