I got json response with the following format :
"/Date(1234)/"
How do I get the numbers only as string (1234) in php ?
thanks
This format /Date(1234)/ usually called JSON Date Format. It contain unixtime with miliseconds. So, when you extract the number you need to divide it to 1000 to get the unixtime and process it in PHP.
Here I give a function to extract the date and convert it to PHP DateTime Object
function parseJSDate($jsDateObject)
{
$dateTime = null;
if (preg_match("/\/Date\((\d+)\)\//", $jsDateObject, $match)) {
if (isset($match[1]) && is_numeric($match[1])) {
$timestamp = (int) $match[1];
$dateTime = new \DateTime();
$dateTime->setTimestamp($timestamp / 1000);
}
}
return $dateTime;
}
$date = parseJSDate("/Date(1224043200000)/");
echo $date->format("Y-m-d H:i:s");
json_decode()