简体   繁体   English

php strtotime返回错误的时间戳

[英]php strtotime return wrong timestamp

I'm using php strtotime function (date format Day, month and two digit year, with dots or tabs dmy from doc: http://www.php.net/manual/en/datetime.formats.date.php ) and found problem: 我正在使用php strtotime功能(日期格式Day, month and two digit year, with dots or tabs带点Day, month and two digit year, with dots or tabs dmy来自doc: http ://www.php.net/manual/en/datetime.formats.date.php)并找到问题:

From php.net example strtotime("30.6.08") -> 1214773200 -> Sun, 29 Jun 2008 21:00:00 GMT(reverse convert right) 来自php.net的例子strtotime(“30.6.08”) - > 1214773200 - > Sun,2008年6月29日21:00:00 GMT(反向转换右)

another variant strtotime("24.10.13") -> 1381180213 -> Mon, 07 Oct 2013 21:10:13 GMT (reverse is not right) 另一种变体strtotime(“24.10.13”) - > 1381180213 - >周一,2013年10月7日21:10:13 GMT(反向不对)

but strtotime("30.10.13") -> 1383084000 -> Tue, 29 Oct 2013 22:00:00 GMT (reverse result again correctly) 但是strtotime(“30.10.13”) - > 1383084000 - > Tue,2013年10月29日22:00:00 GMT(反向结果再次正确)

Whats wrong? 怎么了?

Strtotime is guessing what format you are sending the date in as and guessing wrong. Strtotime正在猜测你发送日期的格式和猜测是错误的。 You should use DateTime() where you can specify the format you are sending the date in as. 您应该使用DateTime() ,您可以在其中指定发送日期的格式。

$date = DateTime::createFromFormat('d.m.y', $datestring);
echo $date->format('Y-m-d');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM