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

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

The command I use is:

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

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

How do I get it to insert the actual one Tand not replace it with EST?

+5
source share
4 answers

Your format should be: "c"

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

From the PHP manual :

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

, , :

$time = date("y-m-d\TH:i:s", time());
+5

You can format the date and time details separately, and then combine the two parts with "T":

<?php
 $time = time(); 
 $time = date( "y-m-d",$time )."T".date( "H:i:s", $time );
?>
+1
source

DATE_ATOM provided for this format:

$theStart_date = date(DATE_ATOM, strtotime($start_date));

Output:

2013-04-10T09:10:30-04:00
+1
source

All Articles