PHP strtotime incorrect conversion

Deadly 提交于 2019-12-06 13:56:50

strtotime is magical, but it's not infallible. If you want to guarantee a proper conversion, you should use

$dt = DateTime::CreateFromFormat('d-m-Y', $startDate);

which lets you specify explicity formats for the input so there's no ambiguity.

Unfortunately, this is PHP 5.3+ only, and you're stuck on 4.1. Even strfptime() which works similary only came in at 5.1

I'd strongly suggest updating your PHP version, as 4.x is deprecated and unsupported.

That being said, I can't see how any kind of conversion ambiguity would convert 2011 into 2008. Timezone differences and day/month oddness would throw off hours and months, but not change things by 3 years.

By default PHP expects that and number-number-number is Y-m-d and works backwards from there until a date makes sense. You may have to change your locale setting: http://ca.php.net/manual/en/class.locale.php. This should fix the European date format error, but keep in mind that the reverse will now be a problem.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!