long rt = System.currentTimeMillis()-(1000*60*60*24*30);
When i convert the above variable rt to date i am not able to get expected date(i.e)30 days before. why?
1000*60*60*24*30 results in int overflow, since it's larger than Integer.MAX_VALUE. Change it to 1000L*60*60*24*30 to use long instead.
For example:
long rt = System.currentTimeMillis()-(1000L*60*60*24*30);
System.out.println (new Date(rt));
prints for me:
Sun Feb 25 09:18:58 IST 2018
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With