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

 

上一篇:c# – 如何在IHttpHandler中捕获特定的HttpException(#0x80072746)


下一篇:Tcpdump MySQL Query