fork(1) 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. import java.time.temporal.* ;
  10. import java.time.chrono.* ;
  11. import java.time.zone.* ;
  12.  
  13.  
  14. /* Name of the class has to be "Main" only if the class is public. */
  15. class Ideone
  16. {
  17. public static void main (String[] args) throws java.lang.Exception
  18. {
  19.  
  20. ZoneId z = ZoneId.of( "Europe/Berlin" ) ;
  21. ZonedDateTime zdt = ZonedDateTime.now( z ) ;
  22. DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.FULL ).withLocale( Locale.GERMANY ) ;
  23. String outputLocalized = zdt.format( f ) ;
  24. Instant instant = zdt.toInstant() ;
  25. long milliseconds = instant.toEpochMilli() ; // Beware of data loss, as any microseconds/nanoseconds are ignored.
  26. String output = instant.truncatedTo( ChronoUnit.MILLIS ).toString() ; // Generate text in standard ISO 8601 format
  27.  
  28. System.out.println( "zdt.toString(): " + zdt ) ;
  29. System.out.println( "instant.toString(): " + instant ) ;
  30. System.out.println( "milliseconds: " + milliseconds ) ;
  31. System.out.println( "output: " + output ) ;
  32.  
  33.  
  34. }
  35. }
Success #stdin #stdout 0.27s 42752KB
stdin
Standard input is empty
stdout
zdt.toString(): 2020-05-09T23:57:35.363701+02:00[Europe/Berlin]
instant.toString(): 2020-05-09T21:57:35.363701Z
milliseconds: 1589061455363
output: 2020-05-09T21:57:35.363Z