View Full Version : Time is a wee bit off...

09-27-2003, 01:02 AM
Umm...I think the time's a wee bit off...7 hours I think:
$time = date("D, F j, g:ia");
I guess this is server time in Atlanta...but I'm in Colorado.
How would I change it without bloating?
Thanks :D

09-27-2003, 03:47 AM
This might sound off-topic, but why not use the JavaScript date function? It will show the time of the users computer instead of the servers time

Just my thought......

09-27-2003, 04:50 AM
$timeis = date('G') - 7;
echo $timeis;

See if you can work from that. It's untested but in my drunken state, it should work in theory :p (PS, that's showing 24 hour hours) See http://uk.php.net/date for more help

09-27-2003, 11:29 AM
wouldn't that show -5 if it was 2am?

$time = date("D, F j, g:ia", time()-25200);

09-27-2003, 08:30 PM
What time do you think is best to use as a reference point in der States?
I'll give it a shot...
PS - Maybe it's Miller time...:cool:

09-27-2003, 11:28 PM
What I'm really looking for is a complete php time/date script that can be included which actually automatically corrects for daylight savings time, finds the correct time regardless of server time, and possibly knows where the user is and corrects for their time...but then again, I'm looking for world peace, too. :rolleyes:

09-28-2003, 12:25 AM
Well, it should be doable. You can grap the users IP, then run a NetGeo search and determinde the regione and timedifference.

There are quite some netgeo classes out there, but about half of the queries returns empty :( . It's a shame.
If it's important to you, you could spend 50$ and get a GeoSelect developpers account.
(look at the bottom, you can return the timezone, and if that isn't accurate enough, also the latitide-longitude)

09-28-2003, 12:37 AM
Ugh...That geobytes includes everything but time zones...
How about if I threw out the time zone location and just set it to EST? So, then it would just need to find the correct time regardless of server time and automatically correct for daylight savings time...A complete set-it-and-forget-it script...
What say?

09-28-2003, 02:48 AM
Handling different time zones and their various daylight saving times is rather difficult. You can change the timezone on linux boxes by setting a certain environment variable. Maybe this works for you on your server (provided it actually is running linux as OS):

putenv("TZ=America/Denver" );
print strftime ("%R");

09-28-2003, 12:09 PM
Originally posted by zoobie
Ugh...That geobytes includes everything but time zones...

I read it returns this (in relation to the IP's city):

But i'm a bit unclear about what you try to do.
With javascript you van grab the users datetime (thoug you'll get nothing for about 10% of the users) or you can ask them about there timesettings (when they register or whatever)

When i'm browsing a site, i really don't need the machine to tell me exactly what time it is. I think you're making it hard on yourself to deliver something the clients isn't interested in. Just my opinion.

09-28-2003, 12:31 PM
Well, I've got it going using mordred's suggestion of strftime() with the %Z for MDT...I guess I'll have to wait another month to see if it changes to MST along with the time, of course.
Where's an online list of locales? I may want to use NYC for EST.
Thanks...Works like a charm...I think. :p

P.S. - I'm not being hard on myself...Actually, this hopefully will take care of "spring forward" and "fall back" time changes automatically 'till the year 2035...heh heh.

P.S.S. - You wouldn't believe the amount of selections available for that function...There's another page with another 30 or so...They must have sat around for a couple of years figuring it all out...It's about time...hee hee. :eek:

09-29-2003, 03:02 AM
It must get it's time from the internet somewhere because it's showing correct Denver time.
I wonder if America/Pacific or America/Eastern wood work...

09-29-2003, 12:08 PM
I found the timezones for the lower 48...

...but can't you set the TZ environment variable and all dates and times will appear correct for the user's timezone with an auto update?

Running a Linux server...

09-30-2003, 12:01 AM
If you have complete control over your linux server, you should be able to set the TZ environment variable through the shell. The exact command to do so doesn't come to my mind right now, but should be easy to find in the manpages/on the net.

However, if you're on shared hosting, I'm afraid that's not gonna be working since you would change the timezone for everyone on that server... und understandably the user in Hawaii doesn't really like having his date() function suddenly return funky values. ;)

Maybe you could put the code I posted into a separate file and include that on every page you need - and to make this procedure easier you could do that automagically by using auto_prepend_file (http://de2.php.net/manual/en/configuration.directives.php#ini.auto-prepend-file) and setting that through a .htaccess file, as shown in the runtime configuration (http://de2.php.net/manual/en/configuration.php) docs.

Hope that helps.

10-02-2003, 06:48 AM
Gotcha...Thanks :D