


Detailed explanation of output formatted date and time examples
We have already understood the syntax of the date() function when we explained the use of the date() function to obtain the current date and time . Here we focus on the formatting of the parameter format of the date() function. options.
The formatting options of parameter format are as follows:
format parameter | Description |
a | lowercase morning value and afternoon value, return value am Or pm |
Capitalized am value and afternoon value, return value am or pm | |
Swatch Internet standard time, return value (000 to 999) | |
The day of the month, two digits with leading 0 (from 01 to 31) | |
Day of the week, text format, 3 letters, return value Mon~Sun | |
Month, complete text format, return value January~December | |
Hour, 12-hour format, no leading zero, return value 1~12 | |
Hour, 24-hour format, no leading zero, return value 0~23 | |
The number of minutes with leading zeros, the return value is 0~59 | |
Determine whether it is daylight saving time, the return value if it is daylight saving time is 1, otherwise 0 | |
The day of the month, no leading zero, return value 1~31 | |
Week number, complete text format, return value Sunday~Saturday | |
Determine whether it is a running year , the return value is 1 if it is a leap year, otherwise it is 0 | |
The month represented by the number, with leading 0, the return value is 01~12 | |
The month represented by the 3-letter abbreviation, the return value Jan~Dec | |
represents the number Month, no leading zero, return value 1~12 | |
The number of hours difference from Greenwich Mean Time, such as +0200 | |
Date in RFC822 format, such as Thu, 21Dec 2000 16:01:07+0200 | ##s |
S | 每月天数后面的英文后缀,两个字符,如st,nd,rd或者th,可以和j一起使用 |
t | 指定月份所应有的天数,28~31 |
T | 本机所在的时区 |
U | 从Unix 纪元(January 1 1970 00:00:00 GMT)开始至今的秒数 |
w | 星期中的第几天,数字表示,返回值0~6 |
W | IOS-8601格式年份中的第几周,每周从星期一开始 |
y | 两位数字表示的年份,返回值如88或08 |
Y |
4位完整数字表示的年份,返回值如 2017,2018 |
z | 年份中的第几天,返回值0~366 |
Z | 以秒为单位的时区偏移量。UTC 以西时区的偏移量为负数(-43200 到 50400) |
实例
date()函数可以对format选项随意地组合。在本例中,既有单独输出一个参数的情况,也有输出多个参数的情况,最好还输出转义字符,实例代码如下:
<?php header("Content-type:text/html;charset=utf-8"); //设置编码 echo "输出单个变量:".date("Y")."-".date("m")."-".date("d")."<br/>"; echo "输出组合变量".date("Y-m-d")."<br/>"; echo "输出更详细的日期和时间".date("Y-m-d H:i:s")."<br/>"; echo "还可以更详细".date("l Y-m-d H:i:s T")."<br/>"; echo "输出转义字符:".date("\T\o\d\a\y \i\s \\t\h\e jS \o\f \y\\e\a\\r"); ?>
运行结果如下图:
上面就是我们对date()函数format参数的格式化实例,下一节,我们讲解“将日期和时间解析为UNIX”时间戳。
The above is the detailed content of Detailed explanation of output formatted date and time examples. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



DOS command is a command line tool used in Windows operating system, which can be used to perform various system management tasks and operations. One of the common tasks is to format the hard drive, including the C drive. Formatting the C drive is a relatively dangerous operation because it will erase all data on the C drive and reinitialize the file system. Before performing this operation, make sure you have backed up important files and have a clear understanding of the impact that formatting will have on your computer. The following is formatted in the DOS command line

How to optimize the performance of time and date formatting and parsing in Java development Summary: In Java development, time and date formatting and parsing are common operations. However, due to the complexity and variety of time and date formats and the huge amount of data processed, it often becomes a performance bottleneck. This article will introduce several methods to optimize the performance of time and date formatting parsing in Java development, including using cache, reducing object creation, selecting appropriate APIs, etc. 1. Introduction Time and date formatting and parsing are very common in Java development. However, in practical applications, since

Disc formatting refers to the process of rebuilding and clearing the disc's file system. During the disc formatting process, all data will be completely deleted, and the file system will be re-established to re-store data on the disc. Disc formatting can be used to protect data security, repair disc failures, and remove viruses. When formatting a disc, you need to back up important data, select an appropriate file system, and wait patiently for the formatting to complete.

The reasons why the D drive cannot be formatted include that the drive is being used by other programs or processes, there is a damaged file system on the drive, hard disk failure and permission issues. Detailed introduction: 1. The reason why the D drive cannot be formatted may be because the drive is being used by other programs or processes. In the Windows operating system, if a program is accessing the files or folders on the D drive, the system will not be able to perform the format operation. ;2. The reason why the D drive cannot be formatted may be because there is a damaged file system on the drive. The file system is used by the operating system to organize and manage files and folders on the storage device, etc.

Use the fmt.Sprint function to format multiple values into strings and return them, including type information. In the Go language, the fmt package provides many functions for formatting data into strings. Among them, the fmt.Sprint function can format multiple values into strings and return them. Unlike the fmt.Sprintf function, the fmt.Sprint function returns a string instead of a formatted string. Here is a simple example code using the fmt.Sprint function: pa

Nowadays, we will inevitably encounter some problems such as being unable to turn on the phone or lagging, such as system crash, but during use, mobile phones have become an indispensable part of our lives. We are often at a loss, and sometimes, there are no solutions to these problems. To help you solve cell phone problems, this article will introduce you to some methods of cell phone format recovery and restore your phone to normal operation. Back up data - protect important information, such as photos and contacts, from being lost during the formatting process. Before formatting your phone, the first thing to consider is to back up important data and files on your phone. To ensure data security, or choose to transfer files to a cloud storage service, you can back it up by connecting to a computer. Use the system's built-in recovery function - simple

How to solve 0x80070057 error: simple and effective methods and steps Introduction: In the process of using the computer, we sometimes encounter various error codes. Among them, 0x80070057 is a very common error code, which is usually related to Windows operating system. This error code can appear in different situations, such as when installing or updating the operating system, backing up or restoring files, formatting drives, etc. Although this error code is frustrating, it's not unsolvable. This article will introduce

Will formatting a laptop make it faster? If you want to format your Windows laptop but want to know if it will make it faster, this article will help you know the right answer to this question. Will formatting a laptop make it faster? There are many reasons why users format their Windows laptops. But the most common reason is slow performance or speed of your laptop. Formatting a laptop will completely delete all data stored on the C drive or the hard drive partition where Windows operating system is installed. Therefore, every user will think twice before taking this step, especially when it comes to the performance of the laptop. This article will help you understand whether formatting your laptop will speed it up. Formatting your laptop helps
