PHP date of date time function details

  • 2020-03-31 20:44:00
  • OfStack

1, year - month - day
Echo date (' Y -m - j);
The 2007-02-6

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

Capital Y represents the four digits of the year, and lowercase Y represents the two digits of the year.
Lowercase m represents the number of months (with leading), and lowercase n represents the number of months without leading.

Echo date (' Y -m - j);
2007 - Feb - 6

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

Capital M represents the three abbreviation characters of the month, while lowercase M represents the number of the month (with a leading 0).
No capital J, only lowercase J for the date of the month, no leading o; Use a lowercase d if you want a month with a leading edge.

Echo date (' Y -m - j);
2007 - Feb - 6

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

Capital M represents the three abbreviations of the month, and capital F represents the month. (no lowercase f)
Capital S indicates the suffix of a date, such as "st", "nd", "rd", and "th", depending on the number of the date.

Summary:
You can use capital Y and lowercase Y for years;
The month can be represented by capital F, capital M, lowercase M, and lowercase n(for characters and Numbers, respectively).
A date can be written with a lowercase d and a lowercase j, and an uppercase S as a suffix for the date.

2. Hour: minute: second

By default, the PHP interpretation displays "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

Lower case g means 12 hours without leading 0, and lower case h means 12 hours with leading 0.
When using the 12-hour system, it is necessary to indicate the afternoon, lowercase a for lowercase "am" and "PM", and uppercase a for uppercase "am" and "PM".

Echo date (' G: I: s');
14:02:26

Capital G represents the number of hours in a 24-hour system, but without a leader; Capital H is used to denote the number of 24 hours with the leading

Summary:
The letter g means hour without a leader, and the letter h means hour with a leader.
Lower case g and h for 12 hours and upper case g and h for 24 hours.

3, leap year, week, day

Echo date (the 'L');
Whether this is a leap year or not: 0

Echo date (the 'l');
Today is Tuesday

Echo date (" D ");
Today is Tue

Capital L indicates whether this year is a leap year or not.
A lowercase l means the day of the week;
The use of capital D for a three - character abbreviation (Tue) of the day of the week.

Echo date (" w ");
Today: 2

Echo date (" W ");
This is the sixth week of the year

A lowercase w is the day of the week
A capital W is 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

A lowercase t is the number of days in the current month
Lowercase z means that today is the day of the year

4, other

Echo date (' T ');
UTC
Capital T represents the time locale of the server

Echo date (" I ");
0
Capital I returns 1 for true or 0 for daylight saving time

Echo date (" U ");
1170769424
Capital U represents the total number of seconds from January 1, 1970 to the present, which is the Unix timestamp for the Unix time epoch.

Echo date (" c ");
The 2007-02-06 T14:24:43 + 00:00
The lowercase c represents the ISO8601 date, the date format is yyyy-mm-dd, the letter T separates the date and time, the time format is HH:MM:SS, and the time zone is represented by the deviation of Greenwich mean time (GMT).

Echo date (" r ");
Tue, 06 Feb 2007 14:25:52 +0000
Lowercase r indicates the date RFC822.

Example:

<?php 
 
$utc=date( " T " ); 
if ($utc== " UTC " ) 
$h=date( " h " )+8; 
$dateshow=date( " Y-m-d  " .$h. " :i:s " ); 
function rn() 
{ 
if (date( " L " )==1) 
{ 
echo  "Yes" ; 
} 
else 
{ 
echo  "No" ; 
} 
} 
$weeks=date( " l " ); 
$year=date( " W " ); 
$dayyear=date( " z " ); 
$weeksmemberic=date( " t " ); 
?> 
<!DOCTYPE html PUBLIC  " -//W3C//DTD XHTML 1.0 Transitional//EN "   " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " > 
<html xmlns= " http://www.w3.org/1999/xhtml " > 
<head> 
<meta http-equiv= " x-ua-compatible "  content= " IE=EmulateIE7 "  /> 
<meta http-equiv= " content-language "  content= " zh-cn "  /> 
<meta http-equiv= " content-type "  content= " text/html; charset=utf-8 "  /> 
<meta http-equiv= " keywords "  content= " date() Function"  /> 
<meta http-equiv= " description "  content= " date() Function"  /> 
<meta http-equiv= " author "  content= " hills "  /> 
<title>date() function </title> 
<link href= " css/default.css "  rel= " stylesheet "  media= " all "  type= " text/css "  /> 
</head> 
<body> 
<div> 
<div> 
<ul> 
<li><?php echo  "The time zone : " .$utc;?></li> 
<li><?php echo  "Current time (+8): " .$dateshow;?></li> 
<li><?php echo ( "Whether a leap year : " ); rn();?></li> 
<li><?php echo  "Week : " .$weeks;?></li> 
<li><?php echo  "Today is the first day of the year : " .$year. "Week" ;?></li> 
<li><?php echo  "Today is the first day of the year." .$dayyear. "Day" ;?></li> 
<li><?php echo  "This month altogether" .$weeksmemberic. "Day" ;?></li> 
</ul> 
</div> 
</div> 
</body> 
</html> 

Related articles: