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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -