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.  
  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. LocalDate ld = LocalDate.of( 2020 , Month.JANUARY , 23 ) ; // 2020-01-23.
  18. LocalTime lt = LocalTime.of( 14 , 30 ) ; // 2:30 PM.
  19. LocalDateTime ldt = LocalDateTime.of( ld , lt ) ;
  20.  
  21. System.out.println( "ldt.toString(): " + ldt ) ;
  22.  
  23. ZoneId z = ZoneId.of( "America/Montreal" ) ;
  24. ZonedDateTime zdt = ldt.atZone( z ) ;
  25.  
  26. System.out.println( "zdt.toString(): " + zdt ) ;
  27.  
  28. Duration d = Duration.ofHours( 1 ) ;
  29. String output = d.toString() ;
  30.  
  31. System.out.println( "output: " + output ) ;
  32.  
  33. }
  34. }
Success #stdin #stdout 0.13s 38440KB
stdin
Standard input is empty
stdout
ldt.toString(): 2020-01-23T14:30
zdt.toString(): 2020-01-23T14:30-05:00[America/Montreal]
output: PT1H