-3

This the epoch mili - 1526581800000

The code which am using for conversion is -

LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(1526581800000),ZoneId.systemDefault());      
System.out.println(localDateTime.format(DateTimeFormatter.ofPattern("dd-MMM-yyyy HH:mm:ss")));

Output which we getting- 17-May-2018 18:30:00

But Expected Output - 18-May-2018 00:00:00

  • 3
    That means your `ZoneId.systemDefault()` is returning the UTC zone. Why do you expect something else then? – f1sh Sep 30 '22 at 13:20
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 30 '22 at 15:37

1 Answers1

2

Well, as already mentioned in a comment, your call to ZoneId.systemDefault() does not return the expected ZoneId. That means you either have to adjust the configuration of your system/JVM or specify a ZoneId manually, like this:

public static void main(String[] args) {
    LocalDateTime localDateTime = LocalDateTime.ofInstant(
                                      Instant.ofEpochMilli(1526581800000L),
                                      ZoneId.of("Asia/Kolkata") // SPECIFY ZONE
                                  );
    System.out.println(
            localDateTime.format(
                    DateTimeFormatter.ofPattern("dd-MMM-yyyy HH:mm:ss",
                                                Locale.ENGLISH)
            )
    );
}

Output (totally independent from the system's time zone):

18-May-2018 00:00:00
deHaar
  • 17,687
  • 10
  • 38
  • 51