note 111532 added to class.datetime

From: Date: Fri, 01 Mar 2013 15:20:11 +0000
Subject: note 111532 added to class.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-193763@lists.php.net to get a copy of this message
There is a subtle difference between the following two statments which causes JavaScript's Date object on iPhones to fail. <?php $objDateTime = new DateTime('NOW'); echo $objDateTime->format('c'); // ISO8601 formated datetime echo $objDateTime->format(DateTime::ISO8601); // Another way to get an ISO8601 formatted string /** On my local machine this results in: 2013-03-01T16:15:09+01:00 2013-03-01T16:15:09+0100 Both of these strings are valid ISO8601 datetime strings, but the latter is not accepted by the constructor of JavaScript's date object on iPhone. (Possibly other browsers as well) */ ?> Our solution was to create the following constant on our DateHelper object. <?php class DateHelper { /** * An ISO8601 format string for PHP's date functions that's compatible with JavaScript's Date's constructor method * Example: 2013-04-12T16:40:00-04:00 * * PHP's ISO8601 constant doesn't add the colon to the timezone offset which is required for iPhone **/ const ISO8601 = 'Y-m-d\TH:i:sP'; } ?> ---- Server IP: 69.147.83.199 Probable Submitter: 95.97.74.180 ---- Manual Page -- http://php.net/manual/en/class.datetime.php Edit -- https://master.php.net/note/edit/111532 Del: integrated -- https://master.php.net/note/delete/111532/integrated Del: useless -- https://master.php.net/note/delete/111532/useless Del: bad code -- https://master.php.net/note/delete/111532/bad+code Del: spam -- https://master.php.net/note/delete/111532/spam Del: non-english -- https://master.php.net/note/delete/111532/non-english Del: in docs -- https://master.php.net/note/delete/111532/in+docs Del: other reasons-- https://master.php.net/note/delete/111532 Reject -- https://master.php.net/note/reject/111532 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193763) next »