Home > php教程 > php手册 > php date()函数各参数详解

php date()函数各参数详解

WBOY
Release: 2016-06-13 11:15:56
Original
963 people have browsed it

在php中date()函数是可以获取时间日期的函数,可能大家常用的就年月日了,下面我来给大分享date()函数一此不为人知的参数。  

date()函数

这个函数就比较熟悉了

 代码如下 复制代码

echo("Result with date():
");
echo(date("l") . "
");
echo(date("l dS of F Y h:i:s A") . "
");
echo("Oct 3,1975 was on a ".date("l", mktime(0,0,0,10,3,1975))."
");
echo(date(DATE_RFC822) . "
");
echo(date(DATE_ATOM,mktime(0,0,0,10,3,1975)) . "

");

echo("Result with gmdate():
");
echo(gmdate("l") . "
");
echo(gmdate("l dS of F Y h:i:s A") . "
");
echo("Oct 3,1975 was on a ".gmdate("l", mktime(0,0,0,10,3,1975))."
");
echo(gmdate(DATE_RFC822) . "
");
echo(gmdate(DATE_ATOM,mktime(0,0,0,10,3,1975)) . "
");
?>

Result with date():
Wednesday
Wednesday 22nd of December 2010 02:36:18 AM
Oct 3,1975 was on a Friday
Wed, 22 Dec 10 02:36:18 +0000
1975-10-03T00:00:00+00:00

Result with gmdate():
Wednesday
Wednesday 22nd of December 2010 02:36:18 AM
Oct 3,1975 was on a Friday
Wed, 22 Dec 10 02:36:18 +0000
1975-10-03T00:00:00+00:00

附上PHP手册里的date()函数参数说明

a - "am" 或是 "pm"
A - "AM" 或是 "PM"
d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31"
D - 星期几,三个英文字母; 如: "Fri"
F - 月份,英文全名; 如: "January"
h - 12 小时制的小时; 如: "01" 至 "12"
H - 24 小时制的小时; 如: "00" 至 "23"
g - 12 小时制的小时,不足二位不补零; 如: "1" 至 12"
G - 24 小时制的小时,不足二位不补零; 如: "0" 至 "23"
i - 分钟; 如: "00" 至 "59"
j - 几日,二位数字,若不足二位不补零; 如: "1" 至 "31"
l - 星期几,英文全名; 如: "Friday"
m - 月份,二位数字,若不足二位则在前面补零; 如: "01" 至 "12"
n - 月份,二位数字,若不足二位则不补零; 如: "1" 至 "12"
M - 月份,三个英文字母; 如: "Jan"
s - 秒; 如: "00" 至 "59"
S - 字尾加英文序数,二个英文字母; 如: "th","nd"
t - 指定月份的天数; 如: "28" 至 "31"
U - 总秒数
w - 数字型的星期几,如: "0" (星期日) 至 "6" (星期六)
Y - 年,四位数字; 如: "1999"
y - 年,二位数字; 如: "99"
z - 一年中的第几天; 如: "0" 至 "365" 


source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template