Home > Backend Development > PHP Tutorial > Arrangement of parameters related to date() date function in PHP_PHP tutorial

Arrangement of parameters related to date() date function in PHP_PHP tutorial

WBOY
Release: 2016-07-21 15:26:37
Original
968 people have browsed it

Add
date_default_timezone_set(PRC) to the front of the page; /*Adjust the time to Beijing time, php5 defaults to Greenwich Mean Time*/
date ()
a: "am" or "pm"
A: "AM" or "PM"
d: Day, two digits, zero if missing; from "01" to "31"
D: Day of the week, 3 English letters, such as: "Fri"
F: month, full English name, such as: "January"
h: hour in 12-hour format, from "01" to "12"
H: Hours in 24-hour format, from "00" to "23"
g: Hours in 12-hour format, no zeros added; from "1" to "12"
G: Hours in 24-hour format, no zeros added Zero; from "0" to "23"
j: a few days, not zero if missing; from "1" to "31"
l: day of the week, full English name, such as: "Friday"
m: month, two digits, from "01" to "12"
n: month, two digits, no zero padding; from "1" to "12"
M: month, 3 English digits Letters; such as: "Jan"
s: seconds; from "00" to "59"
S: add an English ordinal number at the end of the word, two English letters, such as: "21th"
t: specify the month Number of days, from "28" to "31"
U: Total seconds
w: Numeric day of the week, from "0 (Sunday)" to "6 (Saturday)"
Y: Year , four digits
y: year, two digits
z: day of the year; from "1" to "366"
============ ================================================== ====
1, year-month-day
indicates the year with uppercase Y and lowercase y;
indicates the month with uppercase F, uppercase M, lowercase m and lowercase n (respectively representing characters and numbers);
can be used to represent the day with lowercase d or lowercase j, and uppercase S represents the suffix of the date.
echo date('Y-m-j');
2007-02-6
echo date('y-n-j');
07-2-6
Capital Y means the fourth day of the year digits, while lowercase y represents the two-digit number of the year;
lowercase m represents the number of the month (with a leading), while lowercase n represents the number of the month without the leading.
echo date('Y-M-j');
2007-Feb-6
echo date('Y-m-d');
2007-02-06
Capital M represents the month 3 abbreviation characters, and lowercase m represents the number of the month (with a leading 0);
There is no uppercase J, only a lowercase j represents the date of the month, without a leading o; if the month needs a leading, use a lowercase d.
echo date('Y-M-j');
2007-Feb-6
echo date('Y-F-jS');
2007-February-6th
Capital M represents the month 3 abbreviation characters, and capital F represents the full English version of the month. (No lowercase f)
Capital S represents the suffix of the date, such as "st", "nd", "rd" and "th", depending on the date number.
2, hours: minutes: seconds
By default, the time displayed by PHP interpretation is "Greenwich Mean Time", which is 8 hours different from our local time.
echo date('g:i:s a');
5:56:57 am
echo date('h:i:s A');
05:56:57 AM
A lowercase g indicates a 12-hour format without leading 0s, while a lowercase h indicates a 12-hour format with leading 0s.
When using the 12-hour clock, you need to indicate morning and afternoon. Lowercase a represents lowercase "am" and "pm", and uppercase A represents uppercase "AM" and "PM".
echo date('G:i:s');
14:02:26
Capital G represents the hour in 24-hour format, but without leading; use capital H to represent with leading 24-hour hour number
Summary:
The letter g represents the hour without a leading, the letter h represents the hour with a leading;
Lowercase g and h represent the 12-hour format, and uppercase G and H represent the 24-hour format.
3, leap year, week, day
echo date('L');
Whether this year is a leap year: 0
echo date('l');
Today is: Tuesday
echo date('D');
Today is: Tue
Capital L indicates whether this year is a leap year, Boolean value, returns 1 if true, otherwise 0;
Lowercase l indicates the day of the week in English Write in full (Tuesday);
and use a capital D to represent the 3-character abbreviation of the day of the week (Tue).
echo date('w');
Today's week: 2
echo date('W');
This week is the 06th week of the year
Lowercase w represents the day of the week , represented in numerical form
Capital W represents the number of weeks in the year
echo date('t');
This month has 28 days
echo date('z');
Today It is the 36th day of this year
Lowercase t indicates the number of days in the current month
Lowercase z indicates the day of the year today
4, others
echo date('T');
UTC
Capital T indicates the time zone setting of the server
echo date('I');
0
Capital I indicates whether it is daylight saving time, and returns 1 if true, otherwise 0
echo date('U');
1170769424
Uppercase U represents the total number of seconds from January 1, 1970 to the present, which is the UNIX timestamp of the Unix time epoch.
echo date('c');
2007-02-06T14:24:43+00:00
Lowercase c represents ISO8601 date, the date format is YYYY-MM-DD, separated by the letter T Date and time, the time format is HH:MM:SS, and the time zone is expressed using the offset from Greenwich Mean Time (GMT).
echo date('r');
Tue, 06 Feb 2007 14:25:52 +0000
Lowercase r represents the RFC822 date.
5. Format time
echo $row["t_time"]; will output 2008-2-29 12:08:00
echo date("Y-m-d",strtotime($row["t_time" ])); will output 2008-2-29
Note, since the time obtained by $row["t_time"] is already a string, you need to use strtotime (string to timestamp) to convert it, otherwise it will output 1970 -01-01 error

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323943.htmlTechArticleAdd date_default_timezone_set (PRC) to the front page of the page; /*Adjust the time to Beijing time, php5 defaults to Greenwich Mean Time*/ date () a: "am" or "pm" A: "AM" or "PM" d: Day...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template