Java LocalDateTime create from millisecond

Description

Java LocalDateTime create from millisecond

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

public class Main {
  public static void main(String[] argv) throws Exception {
    long l = new Date().getTime();
    System.out.println(ms2LocalDate(l));
  }//from  w w w.j a  va2s  .  c o  m

  public static LocalDateTime ms2LocalDate(final long ms) {
    return LocalDateTime.ofInstant(Instant.ofEpochMilli(ms), ZoneId.systemDefault());
  }
}



PreviousNext

Related