1,324   PHP

1,time(),获取当前时间戳$timestamp

echo time();

 

2,date($format,$timestamp),将时间戳变为字符串;$format为显示样式,$timestamp为时间戳,默认为当前时间戳,本地时区

// 获取本地时区
echo date_default_timezone_get();
// 默认当前时间戳
echo date('Y-m-d H:i:s');
// 前一天
echo date('Y-m-d H:i:s',time()-1*24*60*60);

 

3,strtotime($timestring),将字符串转化为时间戳,$timestring为字符串

// 指定具体时间
echo strtotime('2014-03-01 12:12:00');
// 当前时间
echo strtotime(date('Y-m-d H:i:s'));
// 当前时间加上或者减去相应时间
// + second|minute|hour|day|month|year
// - second|minute|hour|day|month|year
echo strtotime('+1 day');
echo strtotime('-3 hour');

 

4,gmdate($format,$timestamp),将时间戳变为字符串;$format为显示样式,$timestamp为时间戳,默认为当前时间戳,GMT/UTC时区

echo gmdate('Y-m-d H:i:s');
echo gmdate('l,d M Y H:i:s');



Leave a Reply

Your email address will not be published. Required fields are marked *