时间和日期
PHP Date() 函数
格式//
date(format,timestamp)
format |
Required. Specifies the format of the timestamp |
timestamp |
Optional. Specifies a timestamp. Default is the current date and time |
- d - 表示每月的某一天(01 到 31)
- m - 代表一个月(01 到 12)
- Y - 表示一年(四位数字)
- l(小写字母 'L') - 表示星期几
echo “today is ”. date(“y-m-d”) . “<br>”;
php-版权年份
© 2010-<?php echo date(“y”);?>
获取时间
H-24小时制的(00-23);
h-12小时制 ,带前导零(01-12);
i-带前导零的分钟(00-59);
s-带前导零的秒(00-59);
a-Ante meridiem(午前) 和 Post meridiem(午后)(am 或 pm)
echo “this is ”. date(“h:i:sa”);
获取时区
默认定义
Date_default_timezone_set(Asia/Shanghai);
使用mktime创建日期
Date()用于创建时间戳,如果不创建默认可以使用系统格式
mktime(hour, minute, second, month, day, year)
$d=mktime(11, 14, 54, 8, 12, 2014);
echo "Created date is " . date("Y-m-d h:i:sa", $d);
时间的格式转化
strtotime(time, now)
$d=strtotime("10:30pm April 15 2014");
echo "Created date is " . date("Y-m-d h:i:sa", $d);
Strtotime()
将人类可读的函数转化为时间戳
$d=strtotime(“tomorrow”);
Echo date(“y-m-d h:i:sa”,$d)
$d=strtotime("next Saturday");
echo date("Y-m-d h:i:sa", $d) . "<br>";