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. import java.time.temporal.*;
  10.  
  11.  
  12. /* Name of the class has to be "Main" only if the class is public. */
  13. class Ideone
  14. {
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17.  
  18. long millis = System.currentTimeMillis() ;
  19. Instant instant = Instant.ofEpochMilli( millis );
  20.  
  21. ZoneId z = ZoneId.of( "Europe/Rome" );
  22. ZonedDateTime zdt = instant.atZone( z );
  23.  
  24. Locale l = Locale.ITALY ;
  25. DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.SHORT ).withLocale( l ) ;
  26. String output = zdt.format( f );
  27.  
  28. DateTimeFormatter fCustom = DateTimeFormatter.ofPattern( "dd/MM/uuuu HH:mm:ss" ).withLocale( l ) ;
  29. String output2 = zdt.format( fCustom );
  30.  
  31. System.out.println( "millis: " + millis );
  32. System.out.println( "instant.toString(): " + instant );
  33. System.out.println( "zdt.toString(): " + zdt );
  34. System.out.println( "output: " + output );
  35. System.out.println( "output2: " + output2 );
  36.  
  37. }
  38. }
Success #stdin #stdout 0.13s 712192KB
stdin
Standard input is empty
stdout
millis: 1486377378296
instant.toString(): 2017-02-06T10:36:18.296Z
zdt.toString(): 2017-02-06T11:36:18.296+01:00[Europe/Rome]
output: 06/02/17 11.36
output2: 06/02/2017 11:36:18