I have a code where I have to "round" to the lowest minute.
16:05:00
should become16:05:00
16:05:01
should become16:05:00
16:05:29
should become16:05:00
16:05:30
should become16:05:00
16:05:31
should become16:05:00
16:05:59
should become16:05:00
I want to use the DateTime object. There are no functions such as:
setHours()
setMinutes()
setSeconds()
Here's the beginning of my code:
$my_date=DateTime::createFromFormat(
'Y-m-d H:i:s',
$bd_date
);
$my_date->setTimezone(self::$TimeZone);
Now I'd like to set the "seconds" part to zero.
Do you have an elegant way of only setting minutes the way I'd like to?
Nota: I'm not looking for a solution like "divide by getTime() by 60, convert to integer, then multiply by 60". I'm looking for a generic solution to set the seconds, not only to "0".
format
is the only documented way to extract hours from a DateTime. – Weatherspoon