[英]PHP - strtotime is ignoring the year
$date_string = "1 October, 2013";
$date_time = strtotime($date_string); //evaluates to "1412208780"
$date_string_again = date("m/d/y", $date_time); //evaluates to "10/01/14" .. should be "10/01/13"
為什么我的代碼給我錯誤的年份? 我如何解決它?
<?php
$dt = '1 October, 2013';
$date = DateTime::createFromFormat('j F, Y', $dt);
echo $date->format('m/d/Y'); //"prints" 10/01/2013
您的字符串不是strtotime()
識別的有效格式,有關可接受的格式 ,請參見手冊。
如果格式是這樣固定的,則可以使用DateTime::createFromFormat
將日期轉換為DateTime對象。
確實,逗號已將其刪除。 去掉它!
$date_string = "1 October, 2013";
$date_string = str_replace(',','',$date_string);
$date_time = strtotime($date_string);
$date_string_again = date("m/d/y", $date_time);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.