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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

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

In Python, we have some built-in time functions such as strftime() and datetime.now() which can be used to find the time in AM/PM format. Time in AM/PM format is used in a variety of applications such as user interfaces, reporting and documentation, data visualization, and event scheduling. When the time is between 11:59:00 midnight and 12 noon, we say AM time. Similarly, we can say that the time between 12 o'clock and 11:59:00 midnight is PM. The abbreviations AM/PM are used to indicate the exact time. Syntax uses the following syntax in the example &miinus;strftime('%I:%M:%S%p')strft

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

AGson isaJSONlibraryforJava,whichiscreatedbyGoogle.ByusingGson,wecangenerateJSONandconvertJSONtojavaobjects.WecancreateaGsoninstancebycreatingaGsonBuilderinstance and calling withthe create()method.TheGson

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 dates and times using the new DateTimeFormatter class in Java 11 Java 11 introduces a new date and time API that contains many new classes and methods to handle dates and times. Among these new classes, the DateTimeFormatter class is one of the key classes used for formatting and parsing dates and times. In this article, we will explain how to use the DateTimeFormatter class to format dates and times and provide some code

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

In PHP programming, date formatting is a frequently required operation, and is generally accomplished using the date() function. The date() function can format the date according to the external input parameters, and can also operate the timestamp and return the formatted date string. Use the date() function to conveniently format and output the desired date format. The following are some commonly used methods for formatting dates with the date() function: Output date (month-day-year) format echodate('m-d-Y'); //For example

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

PHP is a commonly used programming language used to develop web applications. In the process of developing web applications, it may involve time conversion in different time zones, such as converting American time to Chinese time. This article will detail the steps on how to use PHP to convert American time to Chinese time and provide code examples. 1. Get the US time First, we need to get the US time. The time zone can be set using PHP's built-in function date_default_timezone_set

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 format exception (DateTimeFormatException) Introduction: Java is a widely used programming language, and format exceptions (DateTimeFormatException) are often encountered when processing dates and times. This article will explain how to resolve time formatting exceptions in Java and provide some code examples. 1. What is time formatting exception (DateTimeFormatException) in Java

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 use the TIME_FORMAT function in MySQL to format time into a specific string MySQL is a widely used relational database management system that provides a wealth of functions and operators to process data. In MySQL, there is a very useful function, the TIME_FORMAT function, which can format the time in a specified format and return a string. The basic syntax of the TIME_FORMAT function is as follows: TIME_FORMAT(time,f

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

The PHP date function is an important feature in the PHP language and can implement various time-related functions. In this article, we will summarize the usage of some commonly used PHP date functions to help readers better understand and use them. 1. Get the current time One of the most commonly used functions in PHP date functions is the date() function, which can get the current date and time. Its basic usage is as follows: date(format, timestamp) where the format parameter specifies the format of date and time, t

See all articles