@Brombomb을
귀하의 기능이 잘 작동하지만 한 가지가 당신 잊어 버렸어. 타임 스탬프는 1970년 1월 1일 전에 날짜 부정적 일 수있다, 그래서 우리는 나는이 하나를 사용하는 다른 정규식을
이 필요하고 그것을 잘 작동합니다 :
preg_match('/\/Date\((-?\d+)([+-]\d{4})\)/', $date, $matches);
내가 당신의 기능 약간에 수정 끝에서 나를 위해 더 유용해진다. 내가 다시
- "날짜"=> 날짜에만
- "시간"=> 시간에만
- "날짜"=> 날짜와 시간
- "로 날짜를 얻는 경우에 지금 내가 결정할 수 있습니다 문자열
하고 난 UTC 시간대에 차이를 원한다면 결정할 수 있듯이 문자열 "=> 소인/substracted 첨가 어레이"
가 배열로서 = "날짜 및 시간" 제 3의 매개 변수를주세요 ...
function parseJsonDate($date, $type = 'date', $utc = 0) {
// Match the time stamp (microtime) and the timezone offset (may be + or -) and also negative Timestamps
preg_match('/\/Date\((-?\d+)([+-]\d{4})\)/', $date, $matches);
$seconds = $matches[1]/1000; // microseconds to seconds
$UTCSec = $matches[2]/100*60*60; // utc timezone difference in seconds
if($utc != 0){
$seconds = $seconds + $UTCSec; // add or divide the utc timezone difference
}
$date = date('Y-m-d', $seconds); // only date
$dateTime = date('Y-m-d H:i:s', $seconds); // date and time
$time = date('H:i:s', $seconds); // only time
switch($type)
{
case 'date':
return $date; // returns 'YYYY-MM-DD'
break;
case 'datetime':
return $dateTime; // returns 'YYYY-MM-DD HH:ii:ss'
break;
case 'time':
return $time; // returns 'HH:ii:ss'
break;
case 'array':
$dateArray = str_replace(" ", "-", $dateTime);
$dateArray = str_replace(":", "-", $dateArray);
return explode('-', $dateArray); // return array('YYYY', 'MM', 'DD', 'HH', 'ii', 'SS')
break;
case 'string':
return $matches[1] . $matches[2]; // returns 1336197600000-0600
break;
}
}
04-12-1982는 우연히, 02-15-1982가 아니겠습니까? – hookedonwinter
AinStain의 솔루션 사용 (날짜가 음수 (1970 년 이전) 날짜가 1982-04-13 인 것으로 보이는 경우 필요) –