Tomzie Tomzie - 4 months ago 8
PHP Question

PHP parsing specific date string


call is returning me a date as a string in the following format:


Now, I would like to parse this string into a date object (PHP).

I could use str_replace remove the /Date( and )/ and divide the unix timestamp with 1000, but that seems a bit complicated for this matter to me.

Any thoughts on how I could parse this easily to a date object?


As you said that you want easy way. Yo can use like below;-

    $str = '/Date(1358208000000)/';
    $int = filter_var($str, FILTER_SANITIZE_NUMBER_INT); // get the number only from the string
    echo date ('Y-m-d',($int/1000)); // convert number to seconds and get correct date