note 68499 deleted from ref.datetime by nlopess

From: Date: Fri, 08 Sep 2006 12:01:52 +0000
Subject: note 68499 deleted from ref.datetime by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-116897@lists.php.net to get a copy of this message
Note Submitter: Matt Nordhoff <mnordhoff at gmail dot com> ---- I discovered that, at least in PHP 5.1.2, neither DATE_ATOM or DATE_W3C actually include the colon in the time zone, as the documentation says they do. I wrote a little script to show what all of the constants actually produce and if it's what the documentation says they should. (Remember, this is in PHP 5.1.2.) Here's what it said: DATE_ATOM: 2005-08-15T15:52:01+0000 (different) DATE_COOKIE: Mon, 15 Aug 2005 15:52:01 GMT (different) DATE_ISO8601: 2005-08-15T15:52:01+0000 (same) DATE_RFC822: Mon, 15 Aug 2005 15:52:01 GMT (different) DATE_RFC850: Monday, 15-Aug-05 15:52:01 GMT (different) DATE_RFC1036: Monday, 15-Aug-05 15:52:01 GMT (different) DATE_RFC1123: Mon, 15 Aug 2005 15:52:01 GMT (different) DATE_RFC2822: Mon, 15 Aug 2005 15:52:01 +0000 (same) DATE_RSS: Mon, 15 Aug 2005 15:52:01 GMT (different) DATE_W3C: 2005-08-15T15:52:01+0000 (different) It looks like only DATE_ISO8601 and DATE_RFC2822 produce exactly what they're supposed to. The date() manual page mentions that there is a P format character that outputs the time zone with a colon (at least it's supposed to) starting with PHP 5.1.3. Unfortunately, I'm stuck on 5.1.2, so I guess I'll need to employ a preg_replace() or something to add it. FWIW, here's the script, in case you want to check this: <?php $formats = array( 'ATOM' => array(DATE_ATOM, '2005-08-15T15:52:01+00:00'), 'COOKIE' => array(DATE_COOKIE, 'Monday, 15-Aug-05 15:52:01 UTC'), 'ISO8601' => array(DATE_ISO8601, '2005-08-15T15:52:01+0000'), 'RFC822' => array(DATE_RFC822, 'Mon, 15 Aug 05 15:52:01 +0000'), 'RFC850' => array(DATE_RFC850, 'Monday, 15-Aug-05 15:52:01 UTC'), 'RFC1036' => array(DATE_RFC1036, 'Mon, 15 Aug 05 15:52:01 +0000'), 'RFC1123' => array(DATE_RFC1123, 'Mon, 15 Aug 2005 15:52:01 +0000'), 'RFC2822' => array(DATE_RFC2822, 'Mon, 15 Aug 2005 15:52:01 +0000'), 'RSS' => array(DATE_RSS, 'Mon, 15 Aug 2005 15:52:01 +0000'), 'W3C' => array(DATE_W3C, '2005-08-15T15:52:01+00:00') ); header('Content-Type: text/plain; charset=ISO-8859-1'); foreach ($formats as $format_name => $format_data) { $date = gmdate($format_data[0], 1124121121); // Yes, this is ugly, but you should be able to figure it out with a little concentration. :) echo "DATE_$format_name: $date (".($date === $format_data[1] ? 'same' : 'different').")\n"; } ?>

« previous php.notes (#116897) next »