PHP function date time function date of USES detail

  • 2020-08-22 21:56:14
  • OfStack

The date-time function is a core component of PHP. These functions can be used without installation. The date functions are used in more detail below:

PHP Date () function
The PHP Date() function formats the timestamp into a more readable date and time.

grammar
date(format,timestamp)

format required. Specify the format of the timestamp.
timestamp optional. Specify a time stamp. The default is the current date and time.


Date time function of date()


$t=time();
echo date("Y-m-d H:i:s",$t);
 

The format of the first parameter is respectively:
a - "am" or "pm"
A - "AM" or "PM"
d - a few days, two digits, if less than two digits in front of zero; For example: "01" to "31"
D - Day of the week, 3 Letters; Such as: "Fri"
F - Month, full English name; Such as: "January"
h - 12 hours; For example: "01" to "12"
H - 24 hours; For example: "00" to "23"
For es50EN-12 hour system, zero is not added for less than 2 digits; For example: "1" to "12"
G - 24 hours, less than 2 zero; For example: "0" to "23"
i - minutes; For example: "00" to "59"
j - several days, 2 digits, if less than 2 digits, do not fill zero; For example: "1" to "31"
l - Day of the week, full English name; Such as: "Friday"
m - Month, 2 digits, if less than 2 digits, zero in front; For example: "01" to "12"
n - Month, 2 digits; if less than 2 digits, zero is not added; For example: "1" to "12"
M - Month, 3 Letters; Such as: "Jan"
s - seconds; For example: "00" to "59"
S - with English ordinal and 2 English letters; "th", "nd"
t - The number of days in a specified month; For example: "28" to "31"
U - Total seconds
w - Day of the week, e.g. "0" (Sunday) to "6" (Saturday)
Y - Year, 4-digit; Such as: "1999"
y - year, 2 digits; Such as: "99"
Days in the year OF z-1; For example: "0" to "365"
Other characters not listed above are listed directly for that character

1, year - month - day


echo date('Y-m-j');
2007-02-6

echo date('y-n-j');
07-2-6 


Uppercase Y represents four digits of the year, while lowercase y represents two digits of the year;
Lower case m represents the number of months (with a lead), while lower case n represents the number of months without a lead.


echo date('Y-M-j');
2007-Feb-6

echo date('Y-m-d');
2007-02-06 

Uppercase M represents the three abbreviations for the month, while lowercase m represents the number of the month (with a leading 0);
There is no uppercase J, only lowercase j to indicate the date of month, no leading o; Use lowercase d if you need a guide before the month.


echo date('Y-M-j');
2007-Feb-6

echo date('Y-F-jS');
2007-February-6th 


Capital M represents the three abbreviations of the month, while capital F represents the full English version of the month. (No lower case f)
Capital S refers to date suffixes such as "st", "nd", "rd" and "th" depending on the date number.

Summary:
You can use uppercase Y and lowercase y for the year;
The month can be represented by uppercase F, uppercase M, lowercase m, and lowercase n(two ways of representing characters and Numbers, respectively);
Use lowercase d and lowercase j for the day, and uppercase S for the date suffix.


2, hours: minutes: seconds

By default, PHP interprets the time as "Greenwich Mean Time", which is eight hours away from our local time.


echo date('g:i:s a');
5:56:57 am

echo date('h:i:s A');
05:56:57 AM

The lower case g represents the 12-hour system with no leading 0, while the lower case h represents the 12-hour system with leading 0.
When using the 12-hour system, it is necessary to indicate the afternoon. Lower case a means "am" and "pm" in lower case, and upper case A means "AM" and "PM" in upper case.


echo date('G:i:s');
14:02:26

Capital G refers to the number of hours in a 24-hour system, but without a lead; Use the capital H to indicate the number of hours in a 24-hour system with a lead

Summary:
The letter g means hours with no lead, and h means hours with lead.
Lower case g and h represent the 12-hour system, while upper case G and H represent the 24-hour system.

3, leap year, week, day


echo date('L');
 Leap year or not: 0

echo date('l');
 Today is: Tuesday

echo date('D');
 Today is: Tue

Capital L indicates whether this year is a leap year or not. Boolean value returns 1 if true, 0 if not.
l means what day of the week it is.
The three-character abbreviation for the day of the week (Tue) is used in capital D.


echo date('w');

Today week: 2


echo date('W');

This week is the 06 th week of the year

Lower case w means the day of the week and numerically
Capital W represents the number of weeks in a year

 
echo date('t'); 

This month is 28 days

 
echo date('z'); 

Today is the 36th day of the year

Lower case t represents the number of days in the current month
Lower case z means today is the day of the year

4, other


echo date('T');
UTC 

Uppercase T represents the server's time locale

 
echo date('I');
0 

Capital I means to determine whether the current daylight saving time is, return 1 if true, or 0 if not

 
echo date('U');
1170769424 

The capital U represents the total number of seconds from January 1, 1970 to the present, which is the UNIX timestamp of the Unix time era.

 
echo date('c');
2007-02-06T14:24:43+00:00 

Lower case c represents the ISO8601 date in the form ES249en-ES250en-ES251en, with the letters T to interval the date and time in the form HH:MM:SS and the time zone in the form of Greenwich Mean Time (GMT) deviation.

 
echo date('r');
Tue, 06 Feb 2007 14:25:52 +0000 

Lowercase r represents the RFC822 date.


Related articles: