Web Hosting Talk







View Full Version : Converting timestamps to GMT


AdamsMedia
05-22-2006, 07:18 AM
Just created this for a little script I'm making.
As I'm a coool I thought I'd share it with you guys. =]


<?php

function convert_to_gmt ($timestamp) {
$gmtd = date('O', $timestamp);
$dst = date('I', $timestamp);
$hd = substr($gmtd, 1, 2);
$td = ($hd * (60*60));
if (substr($gmtd, 0, 1) == '-') $timestamp += $td;
elseif (substr($gmtd, 0, 1) == '+') $timestamp -= $td;
if ($dst == 1) $timestamp += (60*60);
return $timestamp;
}

?>


So now all you UK people who buy hosting from the US of A, you can now have British time();

For example,

<?php

function time_gmt () {
$timestamp = time();
$gmtd = date('O', $timestamp);
$dst = date('I', $timestamp);
$hd = substr($gmtd, 1, 2);
$td = ($hd * (60*60));
if (substr($gmtd, 0, 1) == '-') $timestamp += $td;
elseif (substr($gmtd, 0, 1) == '+') $timestamp -= $td;
if ($dst == 1) $timestamp += (60*60);
return $timestamp;
}

?>


time_gmt() will now be a british version of time().

Hope this helps!

netbird
05-30-2006, 10:36 AM
Not only UK people, Portugal too, thanks! :)