나의 시도 솔루션이었다PHP에서 확장 된 날짜 문자열이 주어진다면, 어떻게 월간을 긴 형식으로 추출 할 수 있습니까?
$date = "Nov 30 2009 03:00:00:000PM";
echo date("F Y", strtotime($date));
예상 결과가 있어야한다 "2009년 11월"
다른 간단한 해결책? 정규식 그것을 할 수 있지만
나의 시도 솔루션이었다PHP에서 확장 된 날짜 문자열이 주어진다면, 어떻게 월간을 긴 형식으로 추출 할 수 있습니까?
$date = "Nov 30 2009 03:00:00:000PM";
echo date("F Y", strtotime($date));
예상 결과가 있어야한다 "2009년 11월"
다른 간단한 해결책? 정규식 그것을 할 수 있지만
는, 여기 당신이 이해 할 수 뭔가 쉽게
$date_bad = "Nov 30 2009 03:00:00:000PM";
$piece_date = array();
$piece_date = explode(' ', $date_bad);
$date_good = $piece_date[0] .' '. $piece_date[1] .', '. $piece_date[2] .' ';
$piece_time = array();
$piece_time = explode(':', $piece_date[3]);
// check if the last part contains PM
if (is_numeric(strpos($piece_time[3], 'PM')))
{
$ampm = 'PM';
}
// check if the last part contains AM
elseif (is_numeric(strpos($piece_time[3], 'AM')))
{
$ampm = 'AM';
}
// no AM or PM is there, so it's a 24hr string
else
{
$ampm = '';
}
$date_good .= $piece_time[0] .':'. $piece_time[1] .':'. $piece_time[2] . $ampm;
echo date("F", strtotime($date_good));
date_default_timezone_set ('Etc/GMT-6');
$unixtime = strtotime($date_bad);
$date = date("F Y",$unixtime);
echo $date;
수 없습니다 –
질문의 예제는 이미 strtotime()을 사용했으며 작동하지 않았습니다. – TravisO
'03 : 00 : 00 : 000PM'가 이해되지 않는다. 그 문자열의 소스를'03 : 00 : 00'으로 정정하면'strtotime()'이 효과가 있다고 생각합니다. –
결과가 11 월이기 때문에 질문은 무엇입니까?!?! – TravisO
반환 된 datetime의 소스를 제어 할 수 없습니다. ( – stormist