繁体   English   中英

php strtotime返回错误的时间戳

[英]php strtotime return wrong timestamp

我正在使用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)并找到问题:

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

另一种变体strtotime(“24.10.13”) - > 1381180213 - >周一,2013年10月7日21:10:13 GMT(反向不对)

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

怎么了?

Strtotime正在猜测你发送日期的格式和猜测是错误的。 您应该使用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