How to round DateTime
of Joda
library to the nearest X
minutes ?
For example:
X = 10 minutes Jun 27, 11:32 -> Jun 27, 11
When you want to round Joda DateTime the best solution IMHO is to use the built-in roundHalfCeilingCopy
and roundHalfFloorCopy
methods:
DateTime dateTime = DateTime.now();
DateTime newDateTime = dateTime.minuteOfHour().roundHalfCeilingCopy();
Please note that roundHalfCeilingCopy
will favor the ceiling if halfway. You can use roundHalfFloorCopy
in order to favor the floor in case it's halfway.