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.util.concurrent.TimeUnit ;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15.  
  16. // Parse your input string as a `double`.
  17. String input = "0.36712962962962964";
  18. double fractionOf24Hours = Double.parseDouble ( input );
  19.  
  20. // Calculate the number of nanoseconds in a day.
  21. long nanosIn24Hours = TimeUnit.HOURS.toNanos ( 24 );
  22.  
  23. // Start at time-of-day zero, adding the amount of time in nanos.
  24. long nanosToAdd = ( long ) ( nanosIn24Hours * fractionOf24Hours );
  25. LocalTime localTime = LocalTime.MIN.plusNanos ( nanosToAdd );
  26.  
  27. System.out.println ( "localTime.toString(): " + localTime );
  28.  
  29. }
  30. }
Success #stdin #stdout 0.08s 36664KB
stdin
Standard input is empty
stdout
localTime.toString(): 08:48:40