note 43983 added to function.strtotime
| From: | httpalexandredotalapetitedotnet at rn2 dot php dot net | Date: | Sun, 11 Jul 2004 16:57:30 +0000 |
| Subject: | note 43983 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73055@lists.php.net to get a copy of this message | ||
For versions of PHP that does not integrate that natively, here is a function to transform a W3C
date format (subset of ISO-8601) into a UNIX timestamp:
<?php
function dateW3cToUnix($w3cDT)
{//http://www.w3.org/TR/NOTE-datetime
//1997-07-28T19:25:30.45+01:00
if (strcasecmp('Z',substr($w3cDT,-1,1))==0)
{
$tzd='+00:00';
$myDate=substr($w3cDT,0,-1);
}
else
{
$i=strrpos($w3cDT,'+');
if ($i<1) $i=strrpos($w3cDT,'-');
if (($i>15)&&(strlen($w3cDT)==($i+6)))
{
$tzd=substr($w3cDT,-6);
$myDate=substr($w3cDT,0,-6);
}
else
{
$tzd='+00:00';
$myDate=substr($w3cDT,0,10);
}
}
$lns=strlen($myDate);
$year=($lns>=4)?substr($myDate,0,4):1970;
$month=($lns>=7)?substr($myDate,5,2):1;
$day=($lns>=10)?substr($myDate,8,2):1;
$hour=($lns>=13)?substr($myDate,11,2):0;
$minute=($lns>=16)?substr($myDate,14,2):0;
$second=($lns>=19)?substr($myDate,17,2):0;
$sign=($tzd[0]=='+')?-1:1;
$tzdHour=substr($tzd,1,2);
$tzdMinute=substr($tzd,-2);
$hour+=($tzdHour*$sign);
$minute+=($tzdMinute*$sign);
return gmmktime($hour,$minute,$second,$month,$day,$year);
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43983
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43983&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43983&report=yes
Search -- http://master.php.net/manage/user-notes.php