1//Object Oriented Method
2
3$datetime = new DateTime('2010-12-30 23:21:46');
4
5echo $datetime->format(DateTime::ATOM); // Updated ISO8601
6
7
8//Procedural Method
9
10echo date(DATE_ISO8601, strtotime('2010-12-30 23:21:46'));
1
2FYI: there's a list of constants with predefined formats on the DateTime object, for example instead of outputting ISO 8601 dates with:
3
4<?php
5echo date('c');
6?>
7
8or
9
10<?php
11echo date('Y-m-d\TH:i:sO');
12?>
13
14You can use
15
16<?php
17echo date(DateTime::ISO8601);
18?>
19
20instead, which is much easier to read.
21