note 44063 deleted from function.mktime by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 14 Jul 2004 07:24:24 +0000 |
| Subject: | note 44063 deleted from function.mktime by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73200@lists.php.net to get a copy of this message | ||
Note Submitter: Chirag Shukla
----
mktime can be used in converting GMT to local time. In this case, I am attempting to convert GMT to
CDT (Central Daylight Time). mktime is used in combination with date() function.
<?php
// I am using the convention (assumption) of "07/04/2004 14:45"
$processdate = "07/04/2004 14:45";
// gmttolocal is a function
// i am passing it 2 parameters:
// 1)the date in the above format and
// 2)time difference as a number; -5 in our case
echo gmttolocal($processdate,-5);
function gmttolocal($mydate,$mydifference)
{
// trying to seperate date and time
$datetime = explode(" ",$mydate);
// trying to seperate different elements in a date
$dateexplode = explode("/",$datetime[0]);
// trying to seperate different elements in time
$timeexplode = explode(":",$datetime[1]);
// getting the unix datetime stamp
$unixdatetime = mktime($timeexplode[0]+$mydifference,$timeexplode[1],
0,$dateexplode[0],$dateexplode[1],$dateexplode[2]);
// return the local date
return date("m/d/Y H:i",$unixdatetime));
}
?>