We help IT Professionals succeed at work.
Get Started

Problem adding 30 days worth of milliseconds to time

Last Modified: 2015-03-02
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

Watch Question
Most Valuable Expert 2014
Top Expert 2015
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE