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.* ;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Instant instant = Instant.now() ;
  14. String output = instant.toString() ; // Generates text in ISO 8601 format.
  15.  
  16. System.out.println( output ) ;
  17. System.out.println( instant.toEpochMilli() ) ; // Data loss: Microseconds (and nanoseconds) in an `Instant` go unreported.
  18.  
  19. ZoneId z = ZoneId.of( "Asia/Tokyo" ) ;
  20. ZonedDateTime now = ZonedDateTime.now( z ) ;
  21. String outputZdt = now.toString() ; // ISO 8601 format extended to append name of zone in brackets.
  22.  
  23. System.out.println( outputZdt ) ;
  24. }
  25. }
Success #stdin #stdout 0.14s 49888KB
stdin
Standard input is empty
stdout
2022-11-13T08:51:02.529877Z
1668329462529
2022-11-13T17:51:02.585305+09:00[Asia/Tokyo]