作者:mobiledu2502912017 | 来源:互联网 | 2020-08-27 06:39
在php中可以使用函数“date()”、“strtotime()”以及php原生的时间类来实现时间格式的转换,其中strtotime()函数的使用方法是“strtotime(Y-m-d)”,表示将“Y-m-d”转换为时间戳。
php时间格式转换
将秒转换成时分秒
function cktime($billsec){
$cktime = '';
if($billsec>'0'){
$cktime = gmstrftime('%H:%M:%S',$billsec);
}
return $cktime;
}
生成当前时间戳并按格式显示时间
$time = time();//获取时间戳
$nowtime = date('Y-m-d H:i:s',$time);//生成规定的时间格式
将确切的事件转为时间戳
$oldtime = '2010-11-10 22:19:21';
$catime = strtotime($oldtime);
打印明天此时的时间戳
strtotime(”+1 day“)
打印昨天此时的
strtotime(”-1 day“)
打印下个星期此时的时间戳
strtotime(”+1 week“)
打印指定下星期几的PHP时间戳
strtotime(”next Thursday“)
打印指定上星期几的时间戳
strtotime(”last Thursday“)
推荐教程:《PHP教程》
以上就是php如何进行时间格式的转换的详细内容,更多请关注 第一PHP社区 其它相关文章!