php 时间字符串和时间戳自动格式化[日期]
版权声明:
本文为博主原创文章,转载请声明原文链接...谢谢。o_0。
更新时间:
2017-09-03 11:06:43
温馨提示:
学无止境,技术类文章有它的时效性,请留意文章更新时间,如发现内容有误请留言指出,防止别人"踩坑",我会及时更新文章
传入时间戳或时间格式的字符串都可以自动返回时间字符串,自动判断
/** * 时间戳格式化 * @param int $time * @return string 完整的时间显示 * @author huajie <banhuajie@163.com> */ function time_format($time = NULL, $format = 'Y-m-d H:i:s') { if (preg_match('/\d{1,4}[^\d]+\d{1,2}[^\d]+\d{1,2}(\s+\d{1,2}[^\d]+\d{1,2}[^\d]+\d{1,2})?/', $time)) { return $time; } else { return $time === NULL ? date($format, time()) : ($time ? date($format, $time) : '--'); } }