How to convert date to timestamp in PHP?

前端 未结 19 1890
暗喜
暗喜 2020-11-22 05:38

How do I get timestamp from e.g. 22-09-2008?

19条回答
  •  难免孤独
    2020-11-22 06:27

    If you're looking to convert a UTC datetime (2016-02-14T12:24:48.321Z) to timestamp, here's how you'd do it:

    function UTCToTimestamp($utc_datetime_str)
    {
        preg_match_all('/(.+?)T(.+?)\.(.*?)Z/i', $utc_datetime_str, $matches_arr);
        $datetime_str = $matches_arr[1][0]." ".$matches_arr[2][0];
    
        return strtotime($datetime_str);
    }
    
    $my_utc_datetime_str = '2016-02-14T12:24:48.321Z';
    $my_timestamp_str = UTCToTimestamp($my_utc_datetime_str);
    

提交回复
热议问题