我正在尝试将以下字符串(或当前时间的字符串)转换为时间戳:
Closing date: 02 Apr 15
Closing date: 06 May 15
我的代码如下:
$start_date = explode("Closing date: ", $string);
$start_date = DateTime::createFromFormat('DD M yy', $start_date[1]);
但是当我尝试回显$ start_date-> getTimestamp()时,它告诉我
Fatal error: Call to a member function getTimestamp() on a non-object
对我可能做错的事情有任何想法吗?DD M yy似乎是使用正确的日期格式。
它应该是:
$start_date = explode("Closing date: ", $string);
$start_date = DateTime::createFromFormat('d M y', $start_date[1]);
您需要传递以DateTime::createFromFormat()
帮助解析数据的格式为d M y
。我从文档中提取了信件的意义:
d
和j
:每月的某天,两位数字,带或不带前导零(01
to31
或1
to 31
);F
和M
:一个月的文本表示形式,例如1月或9月(January
通过December
或Jan
通过Dec
);y
:一年的两位数表示形式(假定范围在1970-2069
,包括在内);示例:99
或03
(将分别解释为1999
和2003
)。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句