note 68499 added to ref.datetime

From: Date: Sun, 30 Jul 2006 07:06:42 +0000
Subject: note 68499 added to ref.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-115336@lists.php.net to get a copy of this message
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"; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 69.69.150.251 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/ref.datetime.php Edit -- http://master.php.net/note/edit/68499 Del: integrated -- http://master.php.net/note/delete/68499/integrated Del: useless -- http://master.php.net/note/delete/68499/useless Del: bad code -- http://master.php.net/note/delete/68499/bad+code Del: spam -- http://master.php.net/note/delete/68499/spam Del: non-english -- http://master.php.net/note/delete/68499/non-english Del: in docs -- http://master.php.net/note/delete/68499/in+docs Del: other reasons-- http://master.php.net/note/delete/68499 Reject -- http://master.php.net/note/reject/68499 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#115336) next »