PHP date format /Date(1365004652303-0500)/

后端 未结 10 1127
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 05:56

I am calling an API from where I am getting date /Date(1365004652303-0500)/, I don\'t understand what format this is. How is this date format called? I was not

10条回答
  •  鱼传尺愫
    2020-11-27 06:25

    The following example uses the preg_match() and the DateTime class:

    $date = '/Date(1365004652303-0500)/';
    
    // get the timestamp
    $pattern = '~/Date\(([0-9]*)~';
    preg_match($pattern, $date, $matches);
    $timestamp = round(((int) $matches[1]) / 1000);
    
    $dt = new DateTime();
    $dt->setTimestamp($timestamp);
    
    echo $dt->format('Y-m-d H:i:s');
    

提交回复
热议问题