GMT Date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zeonbay
Forum Newbie
Posts: 3
Joined: Wed Mar 11, 2009 3:28 am

GMT Date

Post by zeonbay »

:banghead:

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.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: GMT Date

Post 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.
zeonbay
Forum Newbie
Posts: 3
Joined: Wed Mar 11, 2009 3:28 am

Re: GMT Date

Post 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
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: GMT Date

Post by Mark Baker »

gmdate()
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: GMT Date

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: GMT Date

Post 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];
}
 
Post Reply