1986年3月30日が1986年3月30日になるような文字列を指定して、完全な日付を取得しようとしています。
次のコードを試しました。
$date = 03.30.1986
$mydate = strtoTime($date);
$printdate = date('m-d-Y', $mydate);
echoを使用して$printdateの結果を表示しましたが、その値がnullであることがわかりました。考え?
$date = '03.30.1986';
$mydate = strtoTime($date);
echo $printdate = date('F d, Y', $mydate);
これは仕事です引用を追加するだけです...
Result :March 31, 1969
$date = '03.30.1986';
$temp = explode('.',$date);
$date = date("m.d.Y", mktime(0, 0, 0, $temp[0], $temp[1],$temp[2]));
echo $date;
php では、ヨーロッパの日付形式と見なされます。詳しくはこちらをご覧ください
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.
私の考え:
strtotime()
文字列が必要です: (関数名$date = "03.30.1986"
の一部に注意してください)str
;
。$date = "03.30.1986";
"F d, Y"
したがって、コードは次のようになります。
$date = "03.30.1986";
$mydate = strtoTime($date);
$printdate = date('F d, Y', $mydate);
最初の行にいくつかのエラー (引用符の欠落、セミコロン) があり、strtotime はその日付形式を解析できず、目的の出力に間違った形式を使用しています。これはうまくいくはずです:
$date = '03.30.1986';
$parts = explode('.', $date);
$mydate = mktime(0, 0, 0, $parts[0], $parts[1], $parts[2]);
$printdate = date('F d, Y', $mydate);