"2012 28 Nov 21:00 CET"
strtotime(“2012年11月28日11:00 21:00 CET”)返回false.
有没有办法将此字符串转换为日期对象,还是需要以不同方式对其进行格式化?
无论如何,DateTime对象有一个方法createFromFormat,它可以更好地解析:
$dt = DateTime::createFromFormat("Y d M H:i T",'2012 28 Nov 21:00 CET'); $ts = $dt->getTimestamp(); echo $ts; // 1354132800
在这里试试:http://codepad.viper-7.com/NfAmcw
strtotime期望“英文文本日期时间”(according to the manual),Y-D-M不是.任何时候strtotime返回false,它只是不理解你的字符串,在这个应用程序中是预期的.手册页上的注释处理此问题:
Note:
Dates in the m/d/y or d-m-y formats are disambiguated by looking at
the separator between the varIoUs components: if the separator is a
slash (/),then the American m/d/y is assumed; whereas if the
separator is a dash (-) or a dot (.),then the European d-m-y format
is assumed.To avoid potential ambiguity,it’s best to use ISO 8601 (YYYY-MM-DD)
dates or DateTime::createFromFormat() when possible.
同样,DateTime是任何与日期或时间交互的优秀工具.
文档
> DateTime类 – http://www.php.net/manual/en/class.datetime.php
> DateTime :: createFromFormat – http://www.php.net/manual/en/datetime.createfromformat.php
> strtotime – http://php.net/manual/en/function.strtotime.php
> date(还列出日期格式字符串) – http://php.net/manual/en/function.date.php
原文地址:https://www.jb51.cc/php/135860.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。