Datetime To Unix timestamp

前端 未结 6 1629
长发绾君心
长发绾君心 2020-12-10 12:22

Is there anyone sitting on a PHP function to convert a date of format 0000-00-00 00:00:00(datetimesql) to unix timestamp?

6条回答
  •  清歌不尽
    2020-12-10 12:47

    I have a solution for you right here:

    /* From MySQL datetime to Unix Timestamp 2003-12-30 23:30:59 -> 1072834230 */
    function convertMysqlDateTimeToUnixTimeStamp($date) {
        $yr=strval(substr($date,0,4));
        $mo=strval(substr($date,5,2));
        $da=strval(substr($date,8,2));
        $hr=strval(substr($date,11,2));
        $mi=strval(substr($date,14,2));
        $se=strval(substr($date,17,2));
        return mktime($hr,$mi,$se,$mo,$da,$yr);
    }
    

提交回复
热议问题