note 43852 deleted from function.strtotime by tomsommer

From: Date: Tue, 06 Jul 2004 16:43:42 +0000
Subject: note 43852 deleted from function.strtotime by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72774@lists.php.net to get a copy of this message
Note Submitter: fboës@dvits.com ---- While reading about the new Web Forms 2.0 (http://whatwg.org/specs/web-forms/current-work/#datetime) I encountered some problems converting ISO8601 to UNIX-Timestamps. This little function below should do the job: <?php function iso8601_to_unix ($iso8601) { // http://whatwg.org/specs/web-forms/current-work/#datetime // $iso8601-format: 1995-12-31T23:59:59.99Z return ( strtotime( substr( str_replace('T',' ',$iso8601) ,0,19 ) .' GMT' ) ); } $t = '2004-06-30T12:58:45.0000Z'; echo (date('Y-m-d H:i:s O',iso8601_to_unix($t))); echo (' or<br/>'); echo (gmdate('Y-m-d H:i:s O',iso8601_to_unix($t))); echo (' should be something like<br/>2004-06-30 14:58:45 +0200'); echo (' or<br/>2004-06-30 12:58:45 +0000'); ?> You may want to change the function-name, though. ;)

« previous php.notes (#72774) next »