fork(3) 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. String input = "08:30:00" ;
  16. LocalTime lt = LocalTime.parse ( input );
  17. Duration d = Duration.between ( LocalTime.MIN , lt );
  18.  
  19. System.out.println( "input: " + input );
  20. System.out.println ( "d.toString(): " + d );
  21.  
  22. ArrayList<Duration> durations = new ArrayList<>( 3 ); // Initial capacity of 3 elements.
  23. durations.add( d ) ;
  24. durations.add( Duration.between ( LocalTime.MIN , LocalTime.parse ( "03:00:00" ) ) ) ;
  25. durations.add( Duration.between ( LocalTime.MIN , LocalTime.parse ( "01:15:00" ) ) ) ;
  26.  
  27. System.out.println( "durations.toString(): " + durations );
  28.  
  29. // You can parse as well as generate standard ISO 8601 strings for duration.
  30. Duration dParsed = Duration.parse( "PT8H30M" );
  31. System.out.println( "dParsed.toString(): " + dParsed );
  32.  
  33. }
  34. }
Success #stdin #stdout 0.09s 711680KB
stdin
Standard input is empty
stdout
input: 08:30:00
d.toString(): PT8H30M
durations.toString(): [PT8H30M, PT3H, PT1H15M]
dParsed.toString(): PT8H30M