jpearson Posted January 11, 2007 Share Posted January 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
Asheeown Posted January 11, 2007 Share Posted January 11, 2007 [code]<?php$Date = date("F j, Y");$Time = date("g:i a");echo "Today's Date: ".$Date."<br />";echo "Server Time: ".$Time."";?>[/code]That will give you for exampleJanuary 9, 2007 4:30 pm Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 use date(); and time()print "Today's date: ".date("d-m-Y", time()+(60*60*5));print "Server Time: ".date("d-m-Y"); Quote Link to comment Share on other sites More sharing options...
DarkendSoul Posted January 11, 2007 Share Posted January 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
jpearson Posted January 11, 2007 Author Share Posted January 11, 2007 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? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.