Reputation: 863
i face problem with System.currentTimeMillis(
) in my project i write some code here where i got problem
Date currentDate = new Date(System.currentTimeMillis());
Log.v("1st",""+currentDate);
Date currentDate = new Date(System.currentTimeMillis()+25*24*60*60*1000);
Log.v("2nd","25th"+currentDate);
it displays current date see in first log but i add 25 days to current date it is in 2nd log but it is not working it displays 2 months back day. it is working very fine in between 1*24*60*60*1000 to 24*24*60*60*1000 days.after 24 it is not working please solve my problem
thanks in advance
Upvotes: 4
Views: 33665
Reputation: 208
25*24*60*60*1000>Integer.MAX_VALUE, your should write as below:
new Date(System.currentTimeMillis()+25*24*60*60*1000l);
Upvotes: 16
Reputation: 157457
use Calendar instead
Calendar rightNow = Calendar.getInstance()
rightNow.add(Calendar.DAY_OF_YEAR, 25)
and the you can get the date object
Upvotes: 9
Reputation: 120498
You are mixing ints and longs. My java is a little rusty, but try:
Date currentDate = new Date(System.currentTimeMillis()+25L*24L*60L*60L*1000L);
Upvotes: 4