PHP Summary of Common Methods for Obtaining Day of the Week
- 2021-11-13 01:00:40
- OfStack
In this paper, an example is given to describe the common method of obtaining the day of the week by PHP. Share it for your reference, as follows:
PHP Day of the week to get the code:
date("l");
//data You can get English weeks, such as Sunday
date("w");
// This can get digital weeks, such as 123 , attention 0 It's Sunday
Get the day of the week in Chinese:
$weekarray=array(" Day ","1","2","3","4","5","6");
// Define first 1 Array of numbers
echo " Week ".$weekarray[date("w")];
// Output: Week 2
Gets the specified date as:
$weekarray=array(" Day ","1","2","3","4","5","6");
echo " Week ".$weekarray[date("w",strtotime("2018-12-18"))];
// Output: Week 2
Because
date
The function is very powerful, and he can be competent for such a job. I attach a table in the manual for easy reference at any time
a | "am" 或是 "pm |
A | "AM" 或是 "PM |
d | 几日,2位数字,若不足2位则前面补零; 如: "01" 至 "31 |
D | 星期几,3个英文字母; 如: "Fri |
F | 月份,英文全名; 如: "January |
h | 12 小时制的小时; 如: "01" 至 "12 |
H | 24 小时制的小时; 如: "00" 至 "23 |
g | 12 小时制的小时,不足2位不补零; 如: "1" 至 12 |
G | 24 小时制的小时,不足2位不补零; 如: "0" 至 "23 |
i | 分钟; 如: "00" 至 "59 |
j | 几日,2位数字,若不足2位不补零; 如: "1" 至 "31 |
l | 星期几,英文全名; 如: "Friday |
m | 月份,2位数字,若不足2位则在前面补零; 如: "01" 至 "12 |
n | 月份,2位数字,若不足2位则不补零; 如: "1" 至 "12 |
M | 月份,3个英文字母; 如: "Jan |
s | 秒; 如: "00" 至 "59 |
S | 字尾加英文序数,2个英文字母; 如: "th","nd |
t | 指定月份的天数; 如: "28" 至 "31 |
U | 总秒数 |
w | 数字型的星期几,如: "0" (星期日) 至 "6" (星期6) |
Y | 年,4位数字; 如: "1999 |
y | 年,2位数字; 如: "99 |
z | 1年中的第几天; 如: "0" 至 "365 |
PS: Here are some time and date related tools for your reference:
Online date/day calculator:
http://tools.ofstack.com/jisuanqi/date_jisuanqi
Online date calculator/difference days calculator:
http://tools.ofstack.com/jisuanqi/datecalc
Online Date-Day Difference Calculator:
http://tools.ofstack.com/jisuanqi/onlinedatejsq
Unix timestamp (timestamp) conversion tool:
http://tools.ofstack.com/code/unixtime
More readers interested in PHP can check the topic of this site: "php Date and Time Usage Summary", "PHP Array (Array) Operation Skills Encyclopedia", "PHP Basic Syntax Introduction Course", "PHP Operation and Operator Usage Summary", "php Object-Oriented Programming Introduction Course", "PHP Network Programming Skills Summary", "php String (string) Usage Summary", "php+mysql Database Operation Introduction Course" and "php Common Database Operation Skills Summary"
I hope this article is helpful to everyone's PHP programming.