-2

这是什么日期格式?

2012-06-08dT00:00:00Z

以及如何将 php 中的时间戳转换为这种日期格式?

4

2 回答 2

2
$dt = new DateTime('2012-06-08T00:00:00Z'); //with no 'd'
$timestamp = $dt->format('U');

如果你必须有'd',那么:

$dt = DateTime::createFromFormat('Y-m-d??H:i:s?', '2012-06-08dT00:00:00Z');
$timestamp = $dt->format('U');

ETA:时间戳->您的格式

$dt = new DateTime('@1339124400');  //the @ indicates the following number is a timestamp
$isoformat= $dt->format('Y-m-d\TH:i:sZ'); //leave out the 'd' and escape the 'T'
于 2012-12-11T14:33:48.150 回答
0

你可以从这里开始:

$date = "2012-06-08dT01:02:03Z";

// parse the date correctly
$parsed_date = date_parse_from_format('Y-m-d  H:i:s ', $date);
print_r($parsed_date);

// Make time from parsed date
$old_date = mktime($parsed_date['hour'], $parsed_date['minute'], $parsed_date['second'], $parsed_date['month'], $parsed_date['day'], $parsed_date['year']);

$now_date = time();

// a silly way to print that parsed date into the original way as before
echo date("Y-m-d", $old_date) . 'dT' . date("H:i:s", $old_date) . 'Z';
echo "\n";

// a silly way to print current date/time in that format
echo date("Y-m-d", $now_date) . 'dT' . date("H:i:s", $now_date) . 'Z';
于 2012-12-11T14:33:12.647 回答