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.ChronoUnit ;
  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. ZoneId z = ZoneId.of( "America/Montreal" ) ;
  17. LocalDate today = LocalDate.now( z ) ;
  18. LocalDate start = today.minusDays( 5 ) ;
  19. LocalDate stop = today.plusDays( 15 ) ;
  20.  
  21. long totalDays = ChronoUnit.DAYS.between( start , stop ) ;
  22. long elapsedDays = ChronoUnit.DAYS.between( start , today ) ;
  23.  
  24. long percentComplete = ( elapsedDays * 100 ) / totalDays ;
  25.  
  26. System.out.println( "start.toString(): " + start ) ;
  27. System.out.println( "today.toString(): " + today ) ;
  28. System.out.println( "stop.toString(): " + stop ) ;
  29. System.out.println( "totalDays: " + totalDays ) ;
  30. System.out.println( "elapsedDays: " + elapsedDays ) ;
  31. System.out.println( percentComplete + "%" ) ;
  32. }
  33. }
Success #stdin #stdout 0.16s 2184192KB
stdin
Standard input is empty
stdout
start.toString(): 2019-06-04
today.toString(): 2019-06-09
stop.toString(): 2019-06-24
totalDays: 20
elapsedDays: 5
25%