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.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14.  
  15. Duration d = Duration.ofHours( 11L ).plusMinutes( 29L ).plusSeconds( 54L ).plusMillis( 999L ) ;
  16. long millis = d.toMillis() ;
  17. String output = d.toString() ;
  18.  
  19. ZoneId z = ZoneId.of( "Pacific/Auckland" ) ;
  20. ZonedDateTime now = ZonedDateTime.now( z ) ;
  21. ZonedDateTime later = now.plus( d ) ;
  22.  
  23. System.out.println( "millis: " + millis ) ;
  24. System.out.println( "output: " + output ) ;
  25. System.out.println( "now.toString(): " + now ) ;
  26. System.out.println( "later.toString(): " + later ) ;
  27.  
  28. }
  29. }
Success #stdin #stdout 0.16s 4386816KB
stdin
Standard input is empty
stdout
millis: 41394999
output: PT11H29M54.999S
now.toString(): 2017-09-27T07:30:34.933+13:00[Pacific/Auckland]
later.toString(): 2017-09-27T19:00:29.932+13:00[Pacific/Auckland]