fork(11) 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.temporal.* ;
  9. import java.time.format.* ;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16.  
  17. // Capture the current moment in UTC, then generate text representing that value in standard ISO 8601 using the `Z` offset-indicator.
  18. String outputZ =
  19. Instant
  20. .now()
  21. .truncatedTo( ChronoUnit.MILLIS )
  22. .toString()
  23. ;
  24.  
  25. String outputZeros =
  26. OffsetDateTime
  27. .now( ZoneOffset.UTC )
  28. .truncatedTo( ChronoUnit.MILLIS )
  29. .format(
  30. DateTimeFormatter.ofPattern( "uuuu-MM-dd'T'HH:mm:ss.SSSxxx" )
  31. )
  32. ;
  33.  
  34.  
  35. System.out.println( "outputZ: " + outputZ ) ;
  36. System.out.println( "outputZeros: " + outputZeros ) ;
  37.  
  38. }
  39. }
Success #stdin #stdout 0.16s 2184192KB
stdin
Standard input is empty
stdout
outputZ: 2019-05-22T21:11:28.970Z
outputZeros: 2019-05-22T21:11:29.078+00:00