时区相关
date_default_timezone_get( ) 获取当前设置时区
date_default_timezone_set(时区) 设置当前时区
备注:我国时区为PRC。
日期相关
date(format[,时间戳])
例子
echo date('Y-m-d H:i:s'); // 2018-03-28 13:20:41
时间戳
time()
返回当前格林威治时间。
字符串转格林威治时间
strtotime(字符串[,时间戳])
例子
// 获取上个月的日期
echo date('Y-m-d H:i:s',strtotime('-1 month'));
echo '<hr/>';
// 上个月的最后一天、第一天
echo date('Y-m-d H:i:s',strtotime('last day of -1 month'));
echo '<br/>';
echo date('Y-m-d H:i:s',strtotime('first day of -1 month'));
echo '<hr/>';
微妙数+时间戳
mircrotime((布尔值))
返回当前微秒数,时间戳;一般用于程序计算时间。
默认顺序:微妙数 时间戳
当参数为true:时间戳.微秒数
时间数组
getdate()
例子
print_r(getdate());
// Array ( [seconds] => 1
[minutes] => 34
[hours] => 13
[mday] => 28
[wday] => 3
[mon] => 3
[year] => 2018
[yday] => 86
[weekday] => Wednesday
[month] => March
[0] => 1522215241
)