fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.time.LocalDateTime;
  7. import java.time.ZonedDateTime;
  8. import java.time.format.DateTimeFormatter;
  9. import java.time.ZoneId;
  10.  
  11.  
  12.  
  13.  
  14. /* Name of the class has to be "Main" only if the class is public. */
  15. class Ideone
  16. {
  17.  
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. Date date = new Date();
  21. System.out.println(date.getTime());
  22.  
  23. System.out.println();
  24.  
  25. LocalDateTime dateTime = LocalDateTime.now();
  26. Date date2 = Date.from(dateTime.atZone(ZoneId.of("America/Sao_Paulo")).toInstant());
  27. System.out.println(date2.getTime());
  28.  
  29. System.out.println();
  30.  
  31. String str = "1986-04-08 12:30";
  32. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  33. LocalDateTime dateTime2 = LocalDateTime.parse(str, formatter);
  34.  
  35. Date date3 = Date.from(dateTime2.atZone(ZoneId.of("Europe/London")).toInstant());
  36. System.out.println(date3.getTime());
  37.  
  38. }
  39. }
Success #stdin #stdout 0.26s 321216KB
stdin
Standard input is empty
stdout
1445956786309

1445963986319

513343800000