编程语言
首页 > 编程语言> > PHP利用preg_split函数格式化日期

PHP利用preg_split函数格式化日期

作者:互联网

// 2018/2/13 00:26:00.000
function format_date($date, $format='Y-m-d H:i:s') {
    if(empty($date)) return $date;
    $arr = preg_split("/[\s\/:.-]+/", $date);
    $year = intval($arr[0]);
    $month = intval($arr[1]);
    $day = intval($arr[2]);
    $hour = intval($arr[3]);
    $minute = intval($arr[4]);
    $second = intval($arr[5]);
    $time = mktime($hour, $minute, $second, $month, $day, $year);
    return date($format, $time);
}
$date = format_date($date);
echo($date);

2018-02-13 00:26:00

 

标签:arr,intval,format,preg,00,month,split,date,PHP
来源: https://www.cnblogs.com/coffee_cn/p/11199106.html