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. import java.time.format.*;
  9. import java.time.temporal.*;
  10.  
  11.  
  12. /* Name of the class has to be "Main" only if the class is public. */
  13. class Ideone
  14. {
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17.  
  18. String inputStart = "08:00:12 pm".toUpperCase() ;
  19. String inputStop = "05:30:12 pm".toUpperCase() ;
  20.  
  21. DateTimeFormatter f = DateTimeFormatter.ofPattern( "hh:mm:ss a" );
  22. LocalTime start = LocalTime.parse( inputStart , f );
  23. LocalTime stop = LocalTime.parse( inputStop , f );
  24.  
  25. Duration d = Duration.between( start , stop );
  26.  
  27. System.out.println( "start.toString(): " + start );
  28. System.out.println( "stop.toString(): " + stop );
  29. System.out.println( "d.toString(): " + d );
  30.  
  31.  
  32. }
  33. }
Success #stdin #stdout 0.17s 4386816KB
stdin
Standard input is empty
stdout
start.toString(): 20:00:12
stop.toString(): 17:30:12
d.toString(): PT-2H-30M