PHPdate format a local time/date _ PHP Tutorial

Source: Internet
Author: User
Tags iso 8601 iso 8601 format
PHPdate format a local time/date. Date (PHP4, PHP5) date format a local time/date description stringdate (string $ format [, int $ timestamp]) returns the string date generated by the integer timestamp according to the given format string

(PHP 4, PHP 5)

Date-format a local time/date

Description: string date (string $ format [, int $ timestamp])

Returns the string generated by the integer timestamp according to the given format string. If no timestamp is provided, the current local time is used. In other words, timestamp is optional and the default value is time ().


Several Useful Constants from PHP 5.1.1 can be used as standard date/time formats to specify the format parameter.


Since PHP 5.1, the timestamp at the TIME when the REQUEST is initiated is saved in $ _ SERVER ['request _ time.


A valid timestamp typically ranges from 20:45:54, January 1, December 13, 1901 to 03:14:07, January 1, January 19, 2038, Greenwich Mean Time. (The value range is the minimum and maximum values of 32-bit signed integers ). However, before PHP 5.1, this range was limited in some systems (such as Windows) from January 1-20, 1970 to January 19.


To convert the time expressed by a string to a timestamp, use strtotime (). In addition, some functions in some databases convert their time formats to timestamps (for example, MySQL's» UNIX_TIMESTAMP function ).

The format string can recognize the strings of the following format parameters
Format Description Return value example
Day --- ---
D The day of the month, which has two digits leading to zero 01 to 31
D The day of the week. The text indicates three letters. Mon to Sun
J The day of the month, with no leading zero 1 to 31
L (lowercase letters of "L) Day of week, complete text format Sunday to Saturday
N The day of the week represented by a number in the ISO-8601 format (new in PHP 5.1.0) 1 (Monday) to 7 (Sunday)
S English suffix after the number of days per month, 2 characters St, nd, rd or th. Can be used with j
W The day of the week, represented by a number 0 (Sunday) to 6 (Saturday)
Z The day of the year. 0 to 366
Week --- ---
W The week of the year in ISO-8601 format, starting from Monday each week (new in PHP 4.1.0) Example: 42 (42nd weeks of the current year)
Month --- ---
F The month in the complete text format, such as January or March. January to December
M Number indicates the month, with a leading zero 01 to 12
M The month abbreviated to three characters. Jan to Dec
N Number indicates the month, with no leading zero 1 to 12
T Number of days in a given month 28 to 31
Year --- ---
L Is it a leap year? If the leap year is 1, otherwise it is 0
O The number of years in ISO-8601 format. This is the same as Y, except that the week number (W) of ISO belongs to the previous year or the next year. (New PHP 5.1.0) Examples: 1999 or 2003
Y The year in which the four digits represent the complete number. Example: 1999 or 2003
Y A two-digit year Example: 99 or 03
Time --- ---
A Morning and afternoon values in lower case Am or pm
A Upper-case morning and afternoon values AM or PM
B Swatch Internet standard 000 to 999
G Hour, 12-hour format, no leading zero 1 to 12
G Hour, in 24-hour format, no leading zero 0 to 23
H Hour, 12-hour format, with leading zero 01 to 12
H Hour, in 24-hour format, with a leading zero 00 to 23
I Minutes with a leading zero 00 to 59>
S Number of seconds, with a leading zero 00 to 59>
Time zone --- ---
E Time zone ID (new in PHP 5.1.0) Example: UTC, GMT, Atlanta/Azores
I When it is enabled or not If this parameter is set to 1, otherwise it is set to 0.
O Hours different from Greenwich Mean Time For example: + 0200
P Difference from Greenwich Mean Time (GMT), separated by colons between hours and minutes (new in PHP 5.1.3) Example: +
T Time zone of the local machine For example, EST and MDT are in full text format in Windows. for example, "Eastern Standard Time" is displayed in Chinese ").
Z The number of seconds of the time difference offset. The time zone offset to the west of UTC is always negative, and the time zone offset to the east of UTC is always positive. -43200 to 43200
Complete date/time --- ---
C Date in ISO 8601 format (new in PHP 5) 2004-02-12T15: 19: 21 + 00: 00
R Date in RFC 822 format Example: Thu, 21 Dec 2000 16:01:07 + 0200
U Number of seconds since Unix epoch (January 1 1970 00:00:00 GMT) See time ()

Unrecognized characters in the format string are displayed as is. The Z format always returns 0 when gmdate () is used.

Http:// (PHP 4, PHP 5) date format a local time/date description stringdate (string $ format [, int $ timestamp]) returns the string produced by the integer timestamp according to the given format string...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.