Home  >  Article  >  Backend Development  >  Detailed explanation of php date() date and time function_PHP tutorial

Detailed explanation of php date() date and time function_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:37:39866browse

1. Year-month-day
echo date('Y-m-j');
2007-02-6

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

Uppercase Y represents the four-digit year, while lowercase y represents the two-digit year;
Lowercase m represents the number of the month (with a leading), while lowercase n represents the month without a leading number.

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

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

Capital M represents the 3 abbreviation characters of the month, while lowercase m represents the number of the month (with leading 0);
There is no uppercase J, only lowercase j represents the date of the month, without leading o; if needed If the month is preceded by a lowercase d, use a lowercase d.

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

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

Capital M represents the 3 abbreviated characters of the month, while capital F represents the full English character 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.

Summary:
can use uppercase Y and lowercase y to represent the year;
can use uppercase F, uppercase M, lowercase m and lowercase n to represent the month (two ways to represent characters and numbers respectively) );
can use lowercase d and lowercase j to represent the day, and uppercase S represents the suffix of the date.

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 the 24-hour format, but without leading; use uppercase The H represents the hour in the 24-hour format with a leading

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, capital G and H represent the 24-hour clock.

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 is 0;
The lowercase l represents the full English version of the day of the week (Tuesday);
The uppercase D is used 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 week 06 of the year

Lowercase w represents the day of the week, expressed in numeric form
Capital W represents the number of weeks in the year

echo date('t');
This month has 28 days

echo date('z');
Today 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 represents the time locale of the server

echo date('I') ;
0
Capital I means to determine whether the current daylight saving time is, if true, return 1, otherwise 0

echo date('U');
1170769424
Capital U means The total number of seconds from January 1, 1970 to the present is the UNIX timestamp of the Unix time epoch.

echo date('c');
2007-02-06T14:24:43+00:00
Lowercase c represents the ISO8601 date, the date format is YYYY-MM-DD, using letters T to separate the date and time, the time format is HH:MM:SS, and the time zone is represented by the offset from Greenwich Mean Time (GMT).

echo date('r');
Tue, 06 Feb 2007 14:25:52 +0000
Lowercase r represents the RFC822 date.

Example:

Copy code The code is as follows:

/*
@author hills
@tencentqq 3303911
@web www.abzz.net
@email hackhgs@qq.com
@blog blog.abzz.net
@mobiletelethone 1345-2626-567
@filecreate 2009-12-25-13:20,copyright hills
*/
$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 “是”;
}
else
{
echo “否”;
}
}
$weeks=date(”l”);
$year=date(”W”);
$dayyear=date(”z”);
$weeksmemberic=date(”t”);
?>









date()函数


















www.bkjia.comtruehttp://www.bkjia.com/PHPjc/321912.htmlTechArticle1,年-月-日 echo date('Y-m-j'); 2007-02-6 echo date('y-n-j'); 07-2-6 大写Y表示年四位数字,而小写y表示年的两位数字; 小写m表示月份的数字(带前导),...
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