We help IT Professionals succeed at work.

Problem adding 30 days worth of milliseconds to time

Found the source of my hairpulling to be that a comparison between  now and (some time in the future) is actually comparing (now) and (some time in the past)  but dont know what is wrong.

For my application, I want to be saving unixtime milliseconds to a record file that is "now" plus 30 days to set an expiry-date, then in the future, comparing that expiry date to 'now'.

Here is the debugging code and output I have.  What am I overlooking or why are the numbers suddenly rolling backwards?  What is a better way to generate the milliseconds time for (now plus 30 days)   ?   Limited to Compiling in Java 7
                long systime = System.currentTimeMillis();
                long newtagex = systime + (1000*60*60*24*30); 
                Date curdate = new Date(systime);
                Date tagdate = new Date(newtagex);
                System.out.println("Current time   " + systime +"  " + curdate.toGMTString());
                System.out.println("Expiry time    " + newtagex + "  " + tagdate.toGMTString());
                System.out.println("plus 60 seconds" + (systime + 1000*60));
                System.out.println("plus 60 min    " + (systime + 1000*60*60));
                System.out.println("plus 24 hrs    " + (systime + 1000*60*60*24));
                System.out.println("plus 30 day    " + (systime + 1000*60*60*24*30));

Open in new window


[01:10:38 INFO]: Current time   1425363038489  3 Mar 2015 06:10:38 GMT
[01:10:38 INFO]: Expiry time    1423660071193  11 Feb 2015 13:07:51 GMT
[01:10:38 INFO]: plus 60 seconds1425363098489
[01:10:38 INFO]: plus 60 min    1425366638489
[01:10:38 INFO]: plus 24 hrs    1425449438489
[01:10:38 INFO]: plus 30 day    1423660071193

Open in new window

Comment
Watch Question

Most Valuable Expert 2014
Top Expert 2015
Commented:
System.out.println("plus 30 day    " + (systime + (long)1000*60*60*24*30));

Author

Commented:
HAH, wow, okay.

Thank you