php 日期相关函数 时间戳 输出时间 其他

1
2
3
date_default_timezone_get();

date_default_timezone_set('PRC');

时间戳

1
time();

得到指定时间的时间戳

1
mktime( [$hour, $min, $sec, $mon, $day, $year]);

将英文文本的日期或时间转换成时间戳

1
2
3
strtotime($time [, $now]);

strtotime('+1 day');

微秒

1
2
3
microtime();     

microtime(true); // 1519217011.4827

输出时间

1
2
3
date($format [, $timestamp]);

date('Y/m/d H:i:s');

其他

  • getdate() 返回包含日期时间的数组

  • gettimeofday() 返回包含时间信息的数组

  • checkdate() 验证时间是否合法