I know lots of people have replied to this suggesting alternative solutions, but if
you want to fix your original solution, all you need to do is put brackets in the
right place - the line which calculates dayDifference should actually be:
double dayDifference =
(nowTs - passwordTs) / (double)TimeStamp.MILLISECONDS_PER_DAY;
instead of
double dayDifference =
(nowTs - passwordTs / (double)TimeStamp.MILLISECONDS_PER_DAY);
because nowTs and passowrd Ts are both in milliseconds. The effect of your original
version was to convert passwordTs into days then subtract it from nowTs in
milliseconds, hence the wrong answer.
Al.
> -----Original Message-----
> From: Cohan, Sean [mailto:[EMAIL PROTECTED]]
> Sent: 20 September 2002 19:20
> To: JDJList
> Subject: [jdjlist] Expiration date.
>
>
> I'm trying to write an equation that lets me know if the
> current date is more than 30 days after a previous date, but
> it's not working out. Can someone show me the way? Here is
> what I have.
>
> public boolean isPasswordExpired() {
> long passwordTs = getPasswordTs().getTime(); // getPasswordTs
> returns a java.util.Date
> long nowTs = new Date().getTime();
>
> int expirationDays = 30;
>
> double dayDifference =
> (nowTs - passwordTs / (double)
> TimeStamp.MILLISECONDS_PER_DAY); // 24 * 60 * 60 * 1000.
>
> if (dayDifference < expirationDays)
> return true;
> return false;
> }
>
>
> getPasswordDt() is returning the 07/07/2002.
>
> I get output similar to the following using printlns:
>
> nowTs = 1032545252875
> passwordTs = 1026057600000
> nowTs - passwordTs / millis per day = 1.0325452409993334E12
>
> Any clues?
>
> Thanks.
>
> To change your JDJList options, please visit:
> http://www.sys-con.com/java/list.cfm
>
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm