PHP strtotime 返回错误结果 [英] PHP strtotime returning wrong results

查看:42
本文介绍了PHP strtotime 返回错误结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

strtotime('3rd January,2010') 在 GMT+5:30 返回 1230993600.

strtotime('3rd January,2010') returns 1230993600 in GMT+5:30.

虽然根据 this,unix 时间戳 1230993600 是 2009 年 1 月 3 日.所以它关闭了一年.

While according to this, unix timestamp 1230993600 is 3rd January,2009. So it's off by one year.

它发生在 PHP 5.2.6 和 5.2.11 上.

It's happening on PHP 5.2.6 as well as 5.2.11 .

推荐答案

问题在于日期字符串中的,.它似乎将日期与字符串中的时间元素分开,如

The problem is the , in the date string. It seems to separate date from time elements in your string, as

echo date('Y-m-d H:i:s', strtotime('3rd January, 2010'));

返回

2009-01-03 20:10:00

echo date('Y-m-d H:i:s', strtotime('3rd January 2010'));

(, removed) 返回正确的日期:

(, removed) returns the correct date:

2010-01-03 00:00:00

这篇关于PHP strtotime 返回错误结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆