java - How do I get the date of 31 days ago? -


how can x should 31 days before current_date?

x(date)___________________________current_date                        31  

just subtract 31 days. example:

localdate current = new localdate(2015, 6, 19); localdate x = current.minusdays(31); // 2015-05-19 

to get current date, use:

localdate current = new localdate(); // default time zone 

or

localdate current = new localdate(zone); // specific zone 

or may want create own "clock" representation able give current instant, in case you'd use:

localdate current = clock.getcurrentinstant().todatetime(zone).tolocaldate(); 

(that lets use dependency injection write simpler unit tests fake clock.)


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -