Given the following PHP code:
$thestring = "Saturday - 05/10/2014 at 10:00 am";
echo $thestring."\n";
$thestring = str_replace("at ", "", $thestring);
echo $thestring."\n";
$thestring = substr($thestring, strpos($thestring, " - ")+3);
echo $thestring."\n";
$thedate = date_create_from_format("m/d/Y h:m a", $thestring);
echo $thedate->format("Ymd")."\n";
echo $thedate->format("Y")."\n";
echo $thedate->format("m")."\n";
echo $thedate->format("d")."\n";
Why am I getting the output below? The month and year are off and I don't see a logical explanation for it.
Saturday - 05/10/2014 at 10:00 am
Saturday - 05/10/2014 10:00 am
05/10/2014 10:00 am
20131210
2013
12
10
m
is the modifier for months. i
is the modifier for minutes. Getting this wrong will obviously cause issues. Change:
$thedate = date_create_from_format("m/d/Y h:m a", $thestring);
to:
$thedate = date_create_from_format("m/d/Y h:i a", $thestring);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加