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.format.* ;
  9.  
  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 current moment.
  18. ZoneId z = ZoneId.of( "America/New_York" ) ;
  19. ZonedDateTime zdt = ZonedDateTime.now( z ) ;
  20.  
  21. // Generate text.
  22. DateTimeFormatter f = DateTimeFormatter.ofPattern( "MM/dd/uuuu HH:mm:ss.SSS" ) ;
  23. String output = zdt.format( f ) ;
  24.  
  25. System.out.println( "zdt.toString(): " + zdt ) ;
  26. System.out.println( "output: " + output ) ;
  27.  
  28. }
  29. }
Success #stdin #stdout 0.16s 2184192KB
stdin
Standard input is empty
stdout
zdt.toString(): 2019-03-04T18:17:08.014-05:00[America/New_York]
output: 03/04/2019 18:17:08.014