fork 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.temporal.* ;
  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. // The easy way.
  16. Instant instant = Instant.ofEpochSecond( 1_602_934_899L ) ;
  17. int h = instant.atOffset( ZoneOffset.UTC ).getHour() ;
  18. Duration d = Duration.between( Instant.EPOCH , instant ) ;
  19.  
  20. System.out.println( instant ) ;
  21. System.out.println( h ) ;
  22. System.out.println( d ) ;
  23. System.out.println( d.toDaysPart() + " days, " + d.toHoursPart() + " hours, " + d.toMinutesPart() + " minutes, " + d.toSecondsPart() + " seconds, " + d.toNanosPart() + " nanos." ) ;
  24.  
  25. // The hard way.
  26. long days = ( 1_602_934_899L / ( 60 * 60 * 24 ) ) ;
  27. long secondsInPartialDay = ( 1_602_934_899L % ( 60 * 60 * 24 ) ) ;
  28. long hour = ( secondsInPartialDay / ( 60 * 60 ) ) ;
  29.  
  30. System.out.println( "days = " + days ) ;
  31. System.out.println( "secondsInPartialDay = " + secondsInPartialDay ) ;
  32. System.out.println( "hour = " + hour ) ;
  33.  
  34. System.out.println(
  35. ( 1_602_934_899L % ( 60 * 60 * 24 ) ) / ( 60 * 60 )
  36. );
  37. }
  38. }
Success #stdin #stdout 0.15s 57348KB
stdin
Standard input is empty
stdout
2020-10-17T11:41:39Z
11
PT445259H41M39S
18552 days, 11 hours, 41 minutes, 39 seconds, 0 nanos.
days = 18552
secondsInPartialDay = 42099
hour = 11
11