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.  
  8. import java.time.*;
  9. import java.time.format.*;
  10. import java.time.temporal.*;
  11. import java.time.zone.*;
  12. import java.util.concurrent.*;
  13.  
  14.  
  15.  
  16. /* Name of the class has to be "Main" only if the class is public. */
  17. class Ideone
  18. {
  19. public static void main (String[] args) throws java.lang.Exception
  20. {
  21.  
  22. ZoneId z = ZoneId.of( "America/Montreal" );
  23.  
  24. // of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneId zone)
  25. ZonedDateTime then = ZonedDateTime.of( 2017 , 1 , 23 , 12 , 34 , 56 , 123456789 , z );
  26.  
  27. ZonedDateTime now = ZonedDateTime.now( z );
  28.  
  29. long days = ChronoUnit.DAYS.between( then , now );
  30.  
  31. System.out.println( "then.toString(): " + then );
  32. System.out.println( "now.toString(): " + now );
  33. System.out.println( "days: " + days );
  34.  
  35. }
  36. }
Success #stdin #stdout 0.15s 4386816KB
stdin
Standard input is empty
stdout
then.toString(): 2017-01-23T12:34:56.123456789-05:00[America/Montreal]
now.toString(): 2017-03-01T21:26:04.884-05:00[America/Montreal]
days: 37