time - Java, easiest way to identify if one week away or one month etc using dates -


after 20 minutes of coding attempt was, if given dd/mm/year , have current dd/mm/year, if difference in years = 0. difference in months = 0 , difference in days = 7, youre 1 week away.

then realized, doesn't take account date wrapping. instance, i'm im given date of 07/01/2017 , current date 06/29/2017. algorithm return false, youre in fact less 1 week away. (depending on month aswell i.e 30 or 31 days).

therefore question is, easiest way check if youre either. 1 month, 2 weeks or 1 week away date when 1) given date , 2) doing time given localdatetime.now()

here example 7 days

localdate old = localdate.of(2017, 6, 29); localdate current = localdate.of(2017, 7, 1);  system.out.println(old.plusdays(7).isbefore(current));  old = localdate.of(2017, 6, 23); system.out.println(old.plusdays(7).isbefore(current)); 

the output be

false true 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -