Page 1 of 1
GMT Date
Posted: Wed Mar 11, 2009 3:32 am
by zeonbay
I was wondering...if there is a way that I can directly get the GMT time WITHOUT considering my server time.
Searched through a lot of forums and scripts, but all of them tend to use the server time as reference.
Probably there is some API function provided by someone whose server time I can trust.
Thanks.
Re: GMT Date
Posted: Wed Mar 11, 2009 3:49 am
by susrisha
http://in2.php.net/manual/en/function.d ... ne-set.php
Lets you set the default time zone to GMT and then set it to your server time or the location.
Re: GMT Date
Posted: Wed Mar 11, 2009 4:50 am
by zeonbay
Thanks susrisha.
But I have a question. If I set the timezone to GMT, I still have to rely on my server time for reference. If my server time changes, my output will be different.
I am looking for a way which will give me the current GMT time even if my server time is different.
For eg. If my server time is 1st Jan 2004 00:00:00, I still want some way by which the current GMT time is fetched.
Is it possible?
Thank you
Re: GMT Date
Posted: Wed Mar 11, 2009 7:22 am
by Mark Baker
gmdate()
Re: GMT Date
Posted: Wed Mar 11, 2009 9:59 am
by pickle
I don't think there's a way to get GMT time without relying on the system clock. You may be able to use a web service, but there's no built-in PHP function for getting a date without relying on the system clock somewhat.
Re: GMT Date
Posted: Wed Mar 11, 2009 12:47 pm
by Mark Baker
pickle wrote:I don't think there's a way to get GMT time without relying on the system clock. You may be able to use a web service, but there's no built-in PHP function for getting a date without relying on the system clock somewhat.
I have a function that does just that: not a web service, but (even better) a time server.
Code: Select all
function query_time_server ($timeserver, $port) {
$timevalue = null;
$fp = fsockopen($timeserver, $port, $err, $errstr, 5);
if ($fp) {
fputs($fp,"\n");
$timevalue = fread($fp,49);
fclose($fp);
}
$ret = array( $timevalue,
$err, // error code
$errstr // error text
);
return($ret);
} // function query_time_server()
$timeserver = "time-C.timefreq.bldrdoc.gov";
$timercvd = query_time_server($timeserver,13);
if (!$timercvd[1]) {
$timevalue = $timercvd[0];
echo 'Time check from time server ',$timeserver,' : [<font color="red">',$timevalue,'</font>]';
} else {
echo 'Unfortunately, the time server $timeserver could not be reached at this time. ';
echo $timercvd[1].' '.$timercvd[2];
}