将 UNIX 时间戳转换为格式化日期字符串

2022-08-30 06:17:14

使用PHP,我想将UNIX时间戳转换为类似于以下内容的日期字符串:2008-07-17T09:24:17Z

如何将时间戳转换为 ?13336994392008-07-17T09:24:17Z


答案 1

像这样尝试gmdate

<?php
$timestamp=1333699439;
echo gmdate("Y-m-d\TH:i:s\Z", $timestamp);
?>

答案 2

使用日期函数date ( string $format [, int $timestamp = time() ] )

用作格式以转换为 ISO 8601 日期(在 PHP 5 中添加)-date('c',time())2012-04-06T12:45:47+05:30

用于获取date("Y-m-d\TH:i:s\Z",1333699439)2012-04-06T13:33:59Z

以下是日期函数支持的一些格式

<?php
$today = date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm
$today = date("m.d.y");                         // 03.10.01
$today = date("j, n, Y");                       // 10, 3, 2001
$today = date("Ymd");                           // 20010310
$today = date('h-i-s, j-m-y, it is w Day');     // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // it is the 10th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:18 m is month
$today = date("H:i:s");                         // 17:16:18
?>

推荐