php false->,php – strtotime返回false

2012年11月28日21:00 CET是一种奇怪的日期/时间格式. Y型d-M?你在哪里得到的?

无论如何,DateTime对象有一个方法createFromFormat,它可以更好地解析:

$dt = DateTime::createFromFormat("Y d M H:i T", '2012 28 Nov 21:00 CET');

$ts = $dt->getTimestamp();

echo $ts; // 1354132800

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是任何与日期或时间交互的优秀工具.

文档

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值