-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 に答える