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. import java.time.*;
  7. import java.time.format.*;
  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. List<String> inputs = new ArrayList<>( 2 );
  15. inputs.add( "141102 0115" );
  16. inputs.add( "141102 0215" );
  17.  
  18. for( String input : inputs ) {
  19. DateTimeFormatter f = DateTimeFormatter.ofPattern( "uuMMdd HHmm" );
  20. LocalDateTime ldt = LocalDateTime.parse( input , f );
  21.  
  22. ZoneId z = ZoneId.of( "America/Montreal" );
  23. ZonedDateTime zdt = ldt.atZone( z );
  24.  
  25. System.out.println( "input: " + input );
  26. System.out.println( "ldt: " + ldt );
  27. System.out.println( "zdt: " + zdt );
  28. System.out.println( "instant: " + zdt.toInstant() );
  29. System.out.println("");
  30. }
  31. }
  32. }
Success #stdin #stdout 0.11s 712192KB
stdin
Standard input is empty
stdout
input: 141102 0115
ldt: 2014-11-02T01:15
zdt: 2014-11-02T01:15-04:00[America/Montreal]
instant: 2014-11-02T05:15:00Z

input: 141102 0215
ldt: 2014-11-02T02:15
zdt: 2014-11-02T02:15-05:00[America/Montreal]
instant: 2014-11-02T07:15:00Z