Web Hosting Talk







View Full Version : PHP Time ... well date()


JustinSmall
01-02-2009, 09:29 PM
print(date("M j Y g:i:s T"));
This prints out:
Jan 2 2009 6:27:09 CST
Which I believe is controlled by the Server.
However, I want to display time by Indiana East (as I am the owner of the website)
Checking my personal clock on my desktop it reads this for the timezone:
(GMT -05:00) Indiana (East)
I know that I will end up having to make a new function, but how would I go about doing that. I'm pretty good with PHP, just not with the PHP date, time functions

headbull
01-02-2009, 09:38 PM
echo "Old Time: ". date("h:i:s")."\n";
putenv("TZ= Europe/Oslo");
echo "New Time: ". date("h:i:s")."\n";
Think that will make the fix your you! :)
Offcourse update the timezone with your zone... This was just an example..

bear
01-02-2009, 09:39 PM
Try this:
http://us.php.net/manual/en/function.date-timezone-set.php
I'd set it for a zone in the US like CA, and use an offset to change it to the one you need.

Jaseeey
01-02-2009, 11:39 PM
You can also use the mktime() function to set the time back by 5 hours if you wish to do it that way.

johnat
01-03-2009, 04:27 AM
You can also use the mktime() function to set the time back by 5 hours if you wish to do it that way.
date("M j Y g:i:s T",mktime()-60*60*5); // 5 hours back in server time
---------------------------
http://www.getbest.info/

JustinSmall
01-03-2009, 11:08 AM
also, is there anyway to display if it was set AM or PM?

JustinSmall
01-03-2009, 02:06 PM
nvm looked in the PHP manual :) got it thanks guys! I should be good from here!

JustinSmall
01-03-2009, 02:26 PM
sorry for double post...
but this is what worked for me.
<?
echo "Server Time: ". date(" h:i:s a\, m/d/Y") ."<br />";
echo "Indiana Time: ". date(" h:i:s a\, m/d/Y",mktime()+60*60*1) ."<br />";
?>
Basically the server time (CST) is an hour behind me (I'm in the weird part of Indiana that has Daylight Savings Time every 10 minutes)
So it works for now, I will keep any eye on it though :P