How to convert date to timestamp in PHP?

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

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

19条回答
  •  攒了一身酷
    2020-11-22 06:20

    Given that the function strptime() does not work for Windows and strtotime() can return unexpected results, I recommend using date_parse_from_format():

    $date = date_parse_from_format('d-m-Y', '22-09-2008');
    $timestamp = mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
    

提交回复
热议问题