php中的时间格式转换函数是strtotime和date,例如将时间戳转换为【Y-m-d H:i:s】,代码为【date("Y-m-d H:i:s",strtotime('2020-08-22'));】。

本教程操作环境:windows10系统、php5.4,本文适用于所有品牌的电脑。
php时间格式转换函数:date()、strtotime()函数,php 原生的时间类也可以转换时间格式。
(学习推荐:php视频教程)
1、Y-m-d转换为时间戳
立即学习“PHP免费学习笔记(深入)”;
例:2017-08-22 转化为时间戳
strtotime(‘2017-08-22’);
2、时间戳转换为Y-m-d H:i:s
date("Y-m-d H:i:s",strtotime('2017-08-22'));3、时间Ymd格式转化为Y-m-d
date(“Y-m-d”,strtotime("20170822"));用原生php类也可以直接转换
var_dum(\DateTime::createFromFormat('Ymd','20170822')->format('Y-m-d'));相关推荐:php培训
以上就是php中的时间格式转换函数是什么的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号