I have time formated as
2007-08-15T02:41:06-0500,
2007-08-12T23:45:36+0800, etc..
I want them all to be at GMT, or even better at my timezone (GMT-7), so I came up with:
function tz_adjust($gmt, $offset)
{
$date = date('Y-m-d H:i:s', strtotime($gmt) + ($offset * 3600));
return $date;
}
$ns_f = '2007-08-15T02:41:06-0500';
$chars = split("T", $ns_f) ;
if (preg_match("/-/",$chars[1])) {
$charsY = split("-", $chars[1]) ;
$gc = "-";
}else{
$charsY = split("-", $chars[1]) ;
$gc = "-";
}
$to2 = preg_split('//', $charsY[1], -1, PREG_SPLIT_NO_EMPTY);
$to3 = $to2[0].$to2[1];
$charsX = $chars[0]." ".$charsY[0];
$goff = $gc.$to3;
echo $ns_f."<BR>";
echo $charsX."<br>";
echo $goff."<br>";
echo tz_adjust($charsX, $goff);
/*
RETURNS
2007-08-15T02:41:06-0500
2007-08-15 02:41:06
-05
2007-08-14 21:41:06
*/
Anyone have a cleaner way or a better way?