I get a return from a JSON date in this format:
/Date(1533524400000-0300)/
How to convoke a DateTime
in PHP?
I get a return from a JSON date in this format:
/Date(1533524400000-0300)/
How to convoke a DateTime
in PHP?
Use this function I found in SOen:
echo parseJsonDate('/Date(1533524400000-0300)/', 'date');
function parseJsonDate($date, $type = 'date') {
preg_match( '/\/Date\((\d+)([+-]\d{4})\)/', $date, $matches); // Match the time stamp (microtime) and the timezone offset (may be + or -)
$date = date( 'm-d-Y', $matches[1]/1000 ); // convert to seconds from microseconds
switch($type){
case 'date':
return $date; // returns '05-04-2012'
break;
case 'array':
return explode('-', $date); // return array('05', '04', '2012')
break;
case 'string':
return $matches[1] . $matches[2]; // returns 1336197600000-0600
break;
}
}
08-06-2018