PHP date and time, PHP date and time_PHP tutorial

WBOY
Release: 2016-07-12 08:56:23
Original
872 people have browsed it

PHP date and time, PHP date and time

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 generates a timestamp for the specified time, prototype:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1113140.htmlTechArticlePHP date and time, PHP date and time 1, date string date ( string $format [, int $timestamp ] ) echo date('Y') . 'br/';// 2016 echo date('y') . 'br/';// 16 echo '------br/'; echo...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template