[英]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.