date_create_from_format不返回预期结果 [英] date_create_from_format does not give back expected result
问题描述
我刚刚尝试过,
date_create_from_format('Ym','201302')
我想是因为今天是29日,实际上是在3月1日还给我。
And I guess because it's the 29th today, it's actually giving me back March 1st.
我希望重新获得 2013-02-01 00:00:00
。
有将正确解析日期的不同功能?如果没有,我可以自己提取它,没什么大不了的。
Is there a different function that will parse a date "correctly"? If not, I can extract it myself, not a big deal.
推荐答案
如果
format
不包含字符!
,然后是未以format指定的生成时间部分
将设置为当前系统时间。
If
format
does not contain the character!
then portions of the generated time which are not specified informat
will be set to the current system time.
如果格式
包含字符!
,然后未以格式
提供的部分生成时间,以及<$左侧的值c $ c>!,将从Unix时代设置为相应的值。
If format
contains the character !
, then portions of the generated time not provided in format
, as well as values to the left-hand side of the !
, will be set to corresponding values from the Unix epoch.
Unix时代是1970-01-01 00:00:00 UTC。
( DateTime手册)
The Unix epoch is 1970-01-01 00:00:00 UTC. (DateTime Manual)
因此,在格式的开头添加
字符串应该可以解决您的问题。!
So, adding a !
at the beginning of your format
string should fix your problem.
这篇关于date_create_from_format不返回预期结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!