How can I format timestamps with embedded `T` character?

pgtips picture pgtips · Feb 13, 2010 · Viewed 15.1k times · Source

I need to format a timestamp in ISO 8601 format (e.g. 2001-10-26T21:32:52). When I use the date() function in PHP, it replaces T with the Timezone (as it is supposed to do).

The command I'm using is:

$time = date("y-m-dTH:i:s", time());

This produces: 10-02-13EST10:21:03

How do I get it to insert an actual T and not replace with EST?

Answer

Patrick Desjardins picture Patrick Desjardins · Feb 13, 2010

Your format shoule be : "c"

$time = date("c", time());

From PHP manual:

Format Descriptions                        Example
c      ISO 8601 date (added in PHP 5)   2004-02-12T15:19:21+00:00