Home  >  Article  >  Backend Development  >  Detailed explanation of the php date() function to obtain the current date and time and formatting method parameters

Detailed explanation of the php date() function to obtain the current date and time and formatting method parameters

怪我咯
怪我咯Original
2017-07-13 10:48:352367browse

date() Function Formats the local date and time and returns the formatted date String.

The following is an example to introduce date() The parameters of the function, the code is as follows

The code is as follows:

<?php echo $showtime=date("Y-m-d H:i:s");?>

Display format: year-month-day hour:minute:second

Related time parameters:

a - "am" or "pm"
A - "AM" Or "PM"
d - day, two digits, if there are less than two digits, add zeros in front; such as: "01" to "31"
D - day of the week, three English letters; such as: "Fri"
F - month, full English name; such as: "January"
h - hour in 12-hour format; such as: "01" to "12"
H - hour in 24-hour format; For example: "00" to "23"
g - For hours in 12-hour format, zeros are not added if there are less than two digits; For example: "1" to 12"
G - For hours in 24-hour format, zeros are not added if there are less than two digits. Fill in zeros; such as: "0" to "23"
i - minutes; such as: "00" to "59"
j - days, two digits, if there are less than two digits, no zeros will be added; such as: "1" to "31"
l - day of the week, full English name; such as: "Friday"
m - month, two digits, if there are less than two digits, add zeros in front; such as: "01" to "12"
n - month, two digits, if there are less than two digits, no zero will be added; such as: "1" to "12"
M - month, three English letters; such as: "Jan"
s - seconds; such as: "00" to "59"
S - add an English ordinal number at the end of the word, two English letters; such as: "th", "nd"
t - specify the number of days in the month ; For example: "28" to "31"
U - Total seconds
w - Numeric day of the week, for example: "0" (Sunday) to "6" (Saturday)
Y - Year , four digits; such as: "1999"
y - year, two digits; such as: "99"
z - the day of the year; such as: "0" to "365"

Example

Format local date and time and return the formatted date string:

<!DOCTYPE html>
<html>
<body><?php
// 输出日
echo date("l") . "<br>";

// 输出日、日期、月、年、时间 AM 或 PM
echo date("l jS \of F Y h:i:s A");
?></body>
</html>

The above is the detailed content of Detailed explanation of the php date() function to obtain the current date and time and formatting method parameters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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