php格式化日期和时间格式化示例分享_PHP教程

WBOY
Release: 2016-07-13 10:24:56
Original
753 people have browsed it

复制代码代码如下:

// 格式化日期
static function formatDate($format, $datetime, $week = 0) {
$datetime = $datetime > 3000 ? $datetime : strtotime($datetime);
if ($week) {
$weeknames = [
'日',
'一',
'二',
'三',
'四',
'五',
'六'
];
$format = str_replace('w', $weeknames [date('w', $datetime)], $format);
}
return date($format, $datetime);
}

复制代码代码如下:

echo "周" . formatDate("w","2012-11-03 00:46:22" , 1) . " " . formatDate("Y-m-d", "2012-11-03 00:46:22");
echo "周" . formatDate("w","1388678400" , 1) . " " . formatDate("Y-m-d", "1388678400");

周六 2012-11-03
周五 2014-01-03

www.bkjia.com true http://www.bkjia.com/PHPjc/825268.html TechArticle 复制代码 代码如下: // 格式化日期 static function formatDate($format, $datetime, $week = 0) { $datetime = $datetime 3000 ? $datetime : strtotime($datetime); if ($week)...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!