fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8. import java.time.format.*;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. /*Instant instant = Instant.parse( "2020-01-23T00:00:00Z" );
  16. ZoneId z = ZoneId.of( "America/Edmonton" );
  17. LocalDate ld = LocalDate.ofInstant( instant , z );
  18.  
  19. System.out.println( "ld.toString() = " + ld );*/
  20. Instant instant = Instant.now();
  21.  
  22. // Convert Instant to LocalDateTime using the system's default time zone
  23. LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
  24.  
  25. // Format LocalDateTime (optional, for custom output)
  26. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yy HH:mm:ss.SSSSSS");
  27. String formattedDateTime = localDateTime.format(formatter);
  28.  
  29. // Print the LocalDateTime (formatted or unformatted)
  30. System.out.println("Instant: " + instant);
  31. System.out.println("LocalDateTime: " + localDateTime);
  32. System.out.println("Formatted LocalDateTime: " + formattedDateTime);
  33. }
  34. }
Success #stdin #stdout 0.23s 56416KB
stdin
Standard input is empty
stdout
Instant: 2025-05-08T14:13:47.168611Z
LocalDateTime: 2025-05-08T14:13:47.168611
Formatted LocalDateTime: 05/08/25 14:13:47.168611