英文:
How to make midnight work in PHP for truncating time?
问题
This doesn't set the time to midnight:
new DateTime('first day of -1 month midnight')
It's the same as if midnight
weren't there.
Tested in PHP 7.3.33 and PHP 8.2.4.
The documentation of time formats isn't very clear. But even if I take an example straight from it, the behavior differs:
echo (new DateTime('yesterday noon'))->format('Y-m-d h:m');
doesn't output noon, the minute field is non-zero.
I've changed the above back to talk about minutes. Which can be accessed with i
, not m
. I attempted to correct it, but, as the comments show, I did it incorrectly, leading to confusion. 12 is indeed noon both with h
and H
. I meant to refer to the hour being 12 at midnight.
英文:
This doesn't set the time to midnight:
new DateTime('first day of -1 month midnight')
It's the same as if midnight
weren't there.
Tested in PHP 7.3.33 and PHP 8.2.4.
The documentation of time formats isn't very clear. But even if I take an example straight from it, the behaviour differs:
echo (new DateTime('yesterday noon'))->format('Y-m-d h:m');
doesn't output noon, the minute field is non-zero.
I've changed the above back to talk about minutes. Which can be accessed with i
, not m
. I attempted to correct it, but, as the comments show, I did it incorrectly, leading to confusion. 12 is indeed noon both with h
and H
. I meant to refer to the hour being 12 at midnight.
答案1
得分: -2
h
提供从 01 到 12 的值
H
提供从 00 到 23 的值,应在此处使用
英文:
h
gives values from 01 to 12
H
gives values from 00 to 23 and should be used here
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论