Elapsed Time with Joda-Time

I have a DateTime object that I need to see if it has passed 10 years or more in the past (think about certificate expiration), I'm new to Joda-Time , how is this done? Thank you for your help.

+3
source share
2 answers

You will want to view the docs for the DateTime class . But in order to make you move, the check will look something like this:

1) You will need to create a DateTime that will be presented 10 years ago ...

// Build a DateTime for exactly 10 years ago.

DateTime tenYearsAgo = new DateTime(); // should give you a DateTime representing 'now' 
tenYearsAgo = tenYearsAgo.minusYears(10);            // should give you 10 years ago

2) ... and use DateTime.isBefore for comparison.

// Let assume the DateTime you're comparing is called 'myDateTime'.

if (myDateTime.isBefore(tenYearsAgo)) { /* do something */ }
else { /* do something else */ }

, , ; , .

+4

Source: https://habr.com/ru/post/1753581/


All Articles