How to make midnight work in PHP to truncate time?
P粉288069045
P粉288069045 2024-04-03 13:48:12
0
1
451

This will not set the time to midnight:

new DateTime('first day of -1 month midnight')

As if midnight does not exist. Tested in PHP 7.3.33 and PHP 8.2.4.

The documentation for the time format is not very clear. But even if I take an example directly from it, the behavior will be different:

echo (new DateTime('yesterday noon'))->format('Y-m-d h:m');

Do not output noon, the minute field is non-zero.

I changed the above back to talking about minutes. Can be accessed using i instead of m. I tried to correct it, but, as the comments indicate, I did it incorrectly, causing confusion. 12 is indeed the noon of H and H. I mean 12 midnight.

P粉288069045
P粉288069045

reply all(1)
P粉545218185

h gives values ​​from 01 to 12

H gives values ​​from 00 to 23, should be used here

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template