Tomzie Tomzie - 1 year ago 71
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?

Answer Source

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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download