在 php 中,您可以使用 date() 函数将 php 时间戳转换为人类可读的日期:使用 date(string $format, int $timestamp = time()) 函数。提供 $format 参数以指定输出日期的格式。可选地提供 $timestamp 参数以指定要转换的 unix 时间戳,默认为当前时间。

将 PHP 时间戳转换为人类可读的日期
在 PHP 中,您可以使用 date() 函数将 UNIX 时间戳转换为人类可读的日期。
语法:
立即学习“PHP免费学习笔记(深入)”;
date(string $format, int $timestamp = time())
参数:
实战案例:
<?php
// 获取当前时间戳
$timestamp = time();
// 将时间戳转换为日期字符串
$dateString = date("Y-m-d H:i:s", $timestamp);
// 输出日期字符串
echo $dateString;
?>输出:
2023-03-07 13:40:15
除了使用 date() 函数,您还可以使用以下函数:
gmdate(): 将时间戳转换为格林威治标准时间 (GMT) 格式。strftime(): 使用更高级的格式字符串来格式化日期。提示:
DateTime 类。以上就是将php时间戳转换为人类可读的日期的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号