What is the date format?

I get this from a specific API:

/Date(-27734400000+0000)/

What format did he name? How to convert it to a timestamp?

+4
source share
1 answer

For some reason, C # seems to serialize such DateTime objects. Usually its format /Date(Seconds since 01/01/1970)/, but the fact that it is negative (and so large) makes me suspect that there was an overflow somewhere. Anyway, something like:

<?php
$str = "/Date(-27734400000+0000)/";
$strTime = substr($str,6,-2);
$date = new \DateTime();
$date->setTimestamp(intval($strTime));
//You can also do some more sophisticated things to set the timezone based on the +xxxx part
print_r($date);

This character prints ( http://sandbox.onlinephpfunctions.com/code/8e65641fa2aae0a3f49ce9c3f27457d7c6842b7b )

DateTime Object (
    [date] => 1091-02-17 16:00:00.000000
    [timezone_type] => 3
    [timezone] => US/Pacific
)

, - 1091. , API, .

+3

Source: https://habr.com/ru/post/1673271/


All Articles