note 43852 added to function.strtotime
| From: | "fbo�s" at dvits dot com | Date: | Tue, 06 Jul 2004 14:29:20 +0000 |
| Subject: | note 43852 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72763@lists.php.net to get a copy of this message | ||
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. ;)
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43852
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43852&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43852&report=yes
Search -- http://master.php.net/manage/user-notes.php