I have a code where I have to “round” to the lowest minute.
16:05:00should become16:05:0016:05:01should become16:05:0016:05:29should become16:05:0016:05:30should become16:05:0016:05:31should become16:05:0016:05:59should 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”.
Is setTime elegant?