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.format.* ;
  9. import java.time.temporal.* ;
  10. import java.time.chrono.* ;
  11. import java.time.zone.* ;
  12.  
  13. /* Name of the class has to be "Main" only if the class is public. */
  14. class Ideone
  15. {
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. long input = 130_016_196_641_685_504L * 10L ;
  19. Instant instant = Instant.EPOCH.plus( input , ChronoUnit.NANOS ) ;
  20.  
  21. System.out.println( "instant.toString(): " + instant ) ;
  22.  
  23. LocalDate ld = LocalDate.of( 2013 , Month.FEBRUARY , 14 ) ;
  24. LocalTime lt = LocalTime.of( 17 , 1 , 4 ) ;
  25. OffsetDateTime odt = OffsetDateTime.of( ld , lt , ZoneOffset.UTC ) ;
  26. long output = Duration.between( Instant.EPOCH , odt.toInstant() ).toNanos() ;
  27.  
  28. System.out.println( "odt.toString(): " + odt ) ;
  29. System.out.println( "output: " + output ) ;
  30.  
  31. }
  32. }
Success #stdin #stdout 0.12s 37344KB
stdin
Standard input is empty
stdout
instant.toString(): 2011-03-15T04:06:06.416855040Z
odt.toString(): 2013-02-14T17:01:04Z
output: 1360861264000000000