0

1986年3月30日が1986年3月30日になるような文字列を指定して、完全な日付を取得しようとしています。

次のコードを試しました。

$date = 03.30.1986
$mydate = strtoTime($date);
$printdate = date('m-d-Y', $mydate);

echoを使用して$printdateの結果を表示しましたが、その値がnullであることがわかりました。考え?

4

5 に答える 5

1
$date = '03.30.1986';
$mydate = strtoTime($date);
echo $printdate = date('F d, Y', $mydate);

これは仕事です引用を追加するだけです...

Result :March 31, 1969
于 2013-01-11T08:51:10.410 に答える
0
$date = '03.30.1986';

$temp = explode('.',$date);

$date = date("m.d.Y", mktime(0, 0, 0, $temp[0], $temp[1],$temp[2]));

echo $date;
于 2013-01-11T08:57:33.220 に答える
0

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.
于 2013-01-11T09:09:48.487 に答える
0

私の考え:

  • strtotime()文字列が必要です: (関数名$date = "03.30.1986"の一部に注意してください)str
  • PHP 式は、次のように区切ります;$date = "03.30.1986";
  • 日付形式を次のように再フォーマットする必要があります。"F d, Y"

したがって、コードは次のようになります。

$date = "03.30.1986";
$mydate = strtoTime($date);
$printdate = date('F d, Y', $mydate);
于 2013-01-11T08:53:12.247 に答える
0

最初の行にいくつかのエラー (引用符の欠落、セミコロン) があり、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);
于 2013-01-11T08:55:08.237 に答える