Home Backend Development PHP Tutorial php格式化日期和时间格式化示例分享_php实例

php格式化日期和时间格式化示例分享_php实例

May 17, 2016 am 08:48 AM
time formatting Format date

复制代码 代码如下:

// 格式化日期
 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

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Python program to format time in AM-PM format Python program to format time in AM-PM format Aug 28, 2023 pm 05:29 PM

Python program to format time in AM-PM format

How to format date using Gson library in Java? How to format date using Gson library in Java? Aug 19, 2023 pm 12:45 PM

How to format date using Gson library in Java?

Format date and time using new DateTimeFormatter class in Java 11 Format date and time using new DateTimeFormatter class in Java 11 Jul 30, 2023 pm 01:49 PM

Format date and time using new DateTimeFormatter class in Java 11

How to use date function to format date in PHP How to use date function to format date in PHP Jun 26, 2023 pm 05:21 PM

How to use date function to format date in PHP

Detailed explanation of the implementation steps of converting American time to Chinese time in PHP Detailed explanation of the implementation steps of converting American time to Chinese time in PHP Mar 27, 2024 pm 06:39 PM

Detailed explanation of the implementation steps of converting American time to Chinese time in PHP

How to solve Java time formatting exception (DateTimeFormatException) How to solve Java time formatting exception (DateTimeFormatException) Aug 26, 2023 pm 04:30 PM

How to solve Java time formatting exception (DateTimeFormatException)

How to format time into a specific string using TIME_FORMAT function in MySQL How to format time into a specific string using TIME_FORMAT function in MySQL Jul 13, 2023 pm 03:55 PM

How to format time into a specific string using TIME_FORMAT function in MySQL

Summary of methods for implementing time-related functions using PHP date functions Summary of methods for implementing time-related functions using PHP date functions Nov 20, 2023 am 11:23 AM

Summary of methods for implementing time-related functions using PHP date functions

See all articles