Jump to content

Timezone problem- pleasehelp


jpearson

Recommended Posts

I have set up a live webcam on my website and the camara is unable to display the current local time on the image itself so I've been attempting to display it with some php.  I live in Peru which is GMT-5 hours and my server time is GMT. This seemingly easy time conversion has resulted to be more difficult than I first thought.
The code I'm currently using to retrieve the server date/time is:

$date_array=getdate();
print"Today's date: ".$date_array['mday']."/".$date_array['mon']."/".$date_array['year'];
print"Server Time: ".$date_array['hours'].":".$date_array['minutes'].":".$date_array['seconds'];

I would appreciate any help anyone could offer on the subject.
Link to comment
Share on other sites

Jesirose's explanation is perfect and correct but I figured I would explain it a bit.

date("d-m-Y", time()+(60*60*5))

Break down :
- date(); the function;
    - First variable ("d-m-Y") the method in which time is displayed. In this case day-month-year all in number format. For more information about how to format go to [url=http://ca.php.net/manual/en/function.date.php]http://ca.php.net/manual/en/function.date.php[/url].
    - time()+(60*60*5) - This part tells the date what to make the date out of. if this field is not added it will take the server time. In this case time() gets the server time in seconds, it then adds 60*60*5 seconds or 5 hours. Changing this part will change the time zone. This is what you want.
Link to comment
Share on other sites

Thanks a lot for your help, and I have it now displaying the date corrected to my time zone (We're currently still the 10th Jan while GMT is the 11th).
In order to to display the local time hh/mm/ss, which arguments do I need to pass to the date() function, if this is even possible?
Link to comment
Share on other sites

That was a very good explanation  Dark. I am not very verbose, so that was good.

jpear: if you look at the page for date you'll see the formatting strings. I think you want H/i/s or G/i/s (although time is normally with : not /, so H:i:s)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.