Sunday, April 13, 2014

Adding second, minute, hour, day to java.util.date


long secondInMilis  = 1000;
long minuteInMilis  = secondInMilis * 60;
long hourInMilis  = minuteInMilis * 60;
long dayInMilis  = hourInMilis * 24;

Date add1Second = new Date(new Date().getTime() + secondInMilis);
Date add10Second = new Date(new Date().getTime() + (10 * secondInMilis));

Date add1Minute = new Date(new Date().getTime() + minuteInMilis);
Date add10Minute = new Date(new Date().getTime() + (10 * minuteInMilis));

Date add1Hour = new Date(new Date().getTime() + hourInMilis);
Date add10Hour = new Date(new Date().getTime() + (10 * hourInMilis));

Date add1Day = new Date(new Date().getTime() + dayInMilis);
Date add10Day = new Date(new Date().getTime() + (10 * dayInMilis));


Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...