Link to home
Start Free TrialLog in
Avatar of thomaszhwang
thomaszhwangFlag for United States of America

asked on

What's the fastest way to change the time based on the following rule in Java?

If time is 4/19/2012 12:34:56, change the time to 4/19/2012 12:30:00.
If time is 4/19/2012 12:36:56, change the time to 4/19/2012 12:35:00.

So basically change the minute part to the last 5-minute time and remove the second.

In MySQL, it would be like:

DATE_SUB(DATE_SUB(aTime, INTERVAL MINUTE(aTime)%5 MINUTE), INTERVAL SECOND(aTime) SECOND)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thomaszhwang

ASKER

Thanks.