输入banner图图片脚本导航/分类

php怎么把时间戳转换为日期格式

在php中可以通过date函数把时间戳转换为日期格式,代码如“date("Y-m-d H:i:s",$coupon.use_start_time)”。

本文操作环境:windows7系统、PHP7.1版、Dell G3电脑。

php怎么把时间戳转换为日期格式?

时间戳转日期 date()

比如

date("Y-m-d H:i:s",$coupon.use_start_time)

{$coupon.use_start_time|date='Y-m-d H:i:s',###}

date — 格式化一个本地时间/日期

说明

date(string $format, int $timestamp = ?): string

返回将整数 timestamp 按照给定的格式字串而产生的字符串。如果没有给出时间戳则使用本地当前时间。换句话说,timestamp 是可选的,默认值为 time()。

小技巧

自 PHP 5.1.1 起有几个有用的常量可用作标准的日期/时间格式来指定 format 参数。

小技巧

自 PHP 5.1 起在 $_SERVER['REQUEST_TIME'] 中保存了发起该请求时刻的时间戳。

注意:

有效的时间戳典型范围是格林威治时间 1901 年 12 月 13 日 20:45:54 到 2038 年 1 月 19 日 03:14:07。(此范围符合 32 位有符号整数的最小值和最大值)。不过在 PHP 5.1 之前此范围在某些系统(如 Windows)中限制为从 1970 年 1 月 1 日到 2038 年 1 月 19 日。

注意:

要将字符串表达的时间转换成时间戳,应该使用 strtotime()。此外一些数据库有一些函数将其时间格式转换成时间戳(例如 MySQL 的 » UNIX_TIMESTAMP 函数)。

推荐学习:《PHP视频教程》

以上就是php怎么把时间戳转换为日期格式的详细内容,更多请关注gxlcms其它相关文章!