Jump to content
xisto Community
Sign in to follow this  
BOAW

Php Server Time

Recommended Posts

i think i may asked this question awhile back but i never really got it solved. ok..i had a block that told me the server time info or whatever. and the GMT wus at 00:00 i wanted to change it to -5:00 but i didnt know how, so how can i change it? im not sure of the codes in the php to change it to the right GMT time becuase im always gettn the wrong times n day

Share this post


Link to post
Share on other sites

I have the same problem. The server I am using is five hours behind my local time and I don't know how to change it. But I have a solution - just leave it at the time it is :)

Share this post


Link to post
Share on other sites

It is usually neccesary to adjust the time whenever you use a php time function since it is common to have the server time set to GMT.
A typical php code to do that would be something like this:

$offset_from_server_time = -6; // a variable defined in the head of the page.. more code here.$my_time = time() + ( 60 * 60 * $offset_from_server_time );.. more code here.

See also:

http://forums.xisto.com/topic/41773-simple-php-calendar-and-yahoo-calendar-connection-linking-each-date-to-yahoo-calendar/

Share this post


Link to post
Share on other sites

it isn't hard or so. you just take the servertime and 'add' -5 hours. and since time() gives seconds, that will be -5*60*60 seconds. so here's an example script:

<?php$timezone = -5;//rather clear, this is your timezone (in hours) (real timezone)$here = time() + $timezone*60*60;//the time in your timezone, long number, so not good for output;)echo gmdate("l j F Y, h:i A", $here);//echo some time?>

gmdate() is exactly the same as date(), but it uses greenwich time, and not servertime. (If using an input time in UNIX-format.)

Cya, Peroim
Edited by peroim (see edit history)

Share this post


Link to post
Share on other sites

Well your script would give you the time double ahead of the GMT time because you guys are subtracting first and then using gmdate.

GMDATE() function requires the current time as per the server.
Then accordingly it will find what are the server settings and convert the time and then give the GMT time.

So your script is now:

gmdate("M d Y H:i:s", mktime())

This is the GMT time as per the server.
However if you make a server change the time would go wrong as gmdate takes the servers time settings.
But on the same server it is just fine.

Hope that helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.