使用PHP,我想将UNIX时间戳转换为类似于此的日期字符串: 2008-07-17T09:24:17Z
2008-07-17T09:24:17Z
如何将时间戳如 1333699439 转换为 2008-07-17T09:24:17Z ?
1333699439
设置默认时区以获得正确的结果非常重要
<?php // set default timezone date_default_timezone_set('Europe/Berlin'); // timestamp $timestamp = 1307595105; // output echo date('d M Y H:i:s Z',$timestamp); echo date('c',$timestamp); ?>
在线转换帮助:http://freeonlinetools24.com/timestamp
$unixtime_to_date = date('jS F Y h:i:s A (T)', $unixtime);
这应该工作 .
<?php $timestamp=1486830234542; echo date('Y-m-d H:i:s', $timestamp/1000); ?>
试试这样的gmdate:
<?php $timestamp=1333699439; echo gmdate("Y-m-d\TH:i:s\Z", $timestamp); ?>
使用日期功能 date ( string $format [, int $timestamp = time() ] )
date ( string $format [, int $timestamp = time() ] )
使用 date('c',time()) 作为格式转换为ISO 8601日期(在PHP 5中添加) - 2012-04-06T12:45:47+05:30
date('c',time())
2012-04-06T12:45:47+05:30
使用 date("Y-m-d\TH:i:s\Z",1333699439) 获取 2012-04-06T13:33:59Z
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 ?>
假设您使用的是PHP5.3,那么处理日期的现代方式是通过原生的DateTime class . 要获得当前时间,您可以致电
$currentTime = new DateTime();
从特定时间戳创建DateTime对象(即不是现在)
$currentTime = DateTime::createFromFormat( 'U', $timestamp );
要获得格式化的字符串,您可以调用
$formattedString = $currentTime->format( 'c' );
见manual page here
我发现这个对话中的信息非常有用,我只想通过使用MySQL数据库中的时间戳和一点PHP来添加我的想法 .
<?= date("Y-m-d\TH:i:s\+01:00",strtotime($column['loggedin'])) ?>
输出结果为:2017-03-03T08:22:36 01:00
非常感谢Stewe你的回答对我来说是一个尤里卡 .
检查这个网址http://www.epochconverter.com/ .
拥有所有语言Epoch和Unix时间戳 .
8 回答
设置默认时区以获得正确的结果非常重要
在线转换帮助:http://freeonlinetools24.com/timestamp
这应该工作 .
试试这样的gmdate:
使用日期功能
date ( string $format [, int $timestamp = time() ] )
使用
date('c',time())
作为格式转换为ISO 8601日期(在PHP 5中添加) -2012-04-06T12:45:47+05:30
使用
date("Y-m-d\TH:i:s\Z",1333699439)
获取2012-04-06T13:33:59Z
以下是日期功能支持的一些格式
假设您使用的是PHP5.3,那么处理日期的现代方式是通过原生的DateTime class . 要获得当前时间,您可以致电
从特定时间戳创建DateTime对象(即不是现在)
要获得格式化的字符串,您可以调用
见manual page here
我发现这个对话中的信息非常有用,我只想通过使用MySQL数据库中的时间戳和一点PHP来添加我的想法 .
输出结果为:2017-03-03T08:22:36 01:00
非常感谢Stewe你的回答对我来说是一个尤里卡 .
检查这个网址http://www.epochconverter.com/ .
拥有所有语言Epoch和Unix时间戳 .