Home > php教程 > php手册 > PHP日期与时间,PHP日期时间

PHP日期与时间,PHP日期时间

WBOY
Release: 2016-06-13 08:43:44
Original
1522 people have browsed it

PHP日期与时间,PHP日期时间

1、date

<span>string</span> <span>date</span> ( <span>string</span> <span>$format</span> [, int <span>$timestamp</span> ] )
Copy after login

                echo date('Y') . '<br/>';// 2016<br />		echo date('y') . '<br/>';// 16<br /><br />		echo '------<br/>';<br /><br />		echo date('m') . '<br/>';// 03<br />		echo date('M') . '<br/>';// Mar, 大写M表示月份的3个缩写字符<br />		echo date('n') . '<br/>';// 3, <br />		echo date('F') . '<br/>';// March, 月份的英文全写<br /><br />		echo '------<br/>';<br /><br />		echo date('d') . '<br/>';// 09<br />		echo date('j') . '<br/>';// 9<br />		echo date('S') . '<br/>';// th,表示日期的后缀。<br /><br />		echo '------<br/>';<br /><br />		echo date('g') . '<br/>';// 4, 12小时制,前不带0<br />		echo date('G') . '<br/>';// 16, 24小时制,带前导0<br />		echo date('H') . '<br/>';// 16,24小时制,前不带0<br />		echo date('h') . '<br/>';// 01, 12小时制,带前导0<br /><br />		echo '------<br/>';<br /><br />		echo date('i') . '<br/>';// 42,分钟<br /><br />		echo '------<br/>';<br /><br />		echo date('s') . '<br/>';// 26,秒<br />		echo date('S') . '<br/>';// th,表示日期的后缀。<br /><br />		echo '------<br/>';<br /><br />		echo date('a') . '<br/>';// pm,小写的am(上午)pm(下午)<br />		echo date('A') . '<br/>';// PM,大写<br /><br />		echo '------<br/>';<br /><br />		echo date('l') . '<br/>';// Thursday,当天是星期几的英文全写(Tuesday)<br />		echo date('L') . '<br/>';// 1,闰年则返回1否则0<br />		echo date('D') . '<br/>';// Thu,表示星期几的3个字符缩写(Tue)<br />	<br /><br />
Copy after login

2、mktime()

​​mktime为指定时间生成时间戳,原型:

int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [,int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1]]]]]]] )
Copy after login

$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));<br />echo "明天是 ".date("Y/m/d", $tomorrow);
Copy after login

3、strtotime()

$d=strtotime("10:38pm April 15 2015");<br />echo "创建日期是 " . date("Y-m-d h:i:sa", $d);<br /><br />$d=strtotime("tomorrow");<br />echo date("Y-m-d h:i:sa", $d) . "<br>";<br /><br />$d=strtotime("next Saturday");<br />echo date("Y-m-d h:i:sa", $d) . "<br>";<br /><br />$d=strtotime("+3 Months");<br />echo date("Y-m-d h:i:sa", $d) . "<br>";<br /><br />​
Copy after login

 

Related labels:
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