fork(6) 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 = "00:10:17" ; // Ambiguously looks like time-of-day but is actually intended as a span-of-time.
  16. Duration d = Duration.between( LocalTime.MIN , LocalTime.parse( input ) ) ;
  17. long milliseconds = d.toMillis() ;
  18.  
  19. System.out.println( "input: " + input );
  20. // TIP: Avoid the HH:MM:SS format for durations (spans of time). Instead use standard ISO 8601 format seen in this next line: PT10M17S
  21. System.out.println( "d.toString(): " + d );
  22. System.out.println( "milliseconds: " + milliseconds );
  23.  
  24. // FYI, `Duration` class can directly parse standard ISO 8601 duration strings.
  25. Duration dParsed = Duration.parse( "PT8H30M" ); // Eight and a half hour duration.
  26.  
  27. }
  28. }
Success #stdin #stdout 0.1s 711680KB
stdin
Standard input is empty
stdout
input: 00:10:17
d.toString(): PT10M17S
milliseconds: 617000