php date() function can obtain the year, month or day of the week by passing in different formatting characters: 1. When the character is "z", you can obtain the day of the year Day; 2. When the character is "d" or "j", the day of the month can be obtained; 3. When the character is "D", "N" or "w", the day of the week can be obtained.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, date() The function can format a timestamp and obtain the day of the week, month, or year.
Syntax:
date("格式化字符"[,时间戳])
The second parameter can be omitted, then it is the current date and time.
There are three formatting characters for getting the day of the year:
The day of the year
z: Range 0 to 365
The day of the month
d: With leading 2 digits of zero, range 01 to 31
j: no leading zero, range 1 to 31
Day of the week
D: text representation, 3 letters, range Mon to Sun
N: ISO-8601 format number Indicates the day of the week (newly added in PHP 5.1.0), ranging from 1 (indicating Monday) to 7 (indicating Sunday)
w: numerical representation, range 0 ( Indicates Sunday) to 6 (indicates Saturday)
Example 1:
<?php header('content-type:text/html;charset=utf-8'); echo "今天是一年的第 ".date("z"). " 天<br>"; ?>
<?php header('content-type:text/html;charset=utf-8'); echo "今天是5月的第 ".date("d"). " 天<br>"; echo "今天是5月的第 ".date("j"). " 天<br>"; ?>
##Example 3:
<?php header('content-type:text/html;charset=utf-8'); echo "今天是一周的第 ".date("D"). " 天<br>"; echo "今天是一周的第 ".date("N"). " 天<br>"; echo "今天是一周的第 ".date("w"). " 天<br>"; ?>
Recommended study: "
The above is the detailed content of How to use date in php to get the day. For more information, please follow other related articles on the PHP Chinese website!