Page 1 of 1

Date(); Wrong Time Zone

Posted: Sat Aug 09, 2003 10:43 pm
by Shiro
Im using Date("m/d/y"); and its off by a day right now its saying its the 10th when its really the 9th any way i can set it to PST?

Posted: Sat Aug 09, 2003 11:00 pm
by oldtimer
What is the web server set at. This is really where it takes the time at. Try a date("m/d/y H:i T"); and see what time it says.

Yeah

Posted: Sat Aug 09, 2003 11:12 pm
by Shiro
Yeah its In Europe so X( is there any way i can get it to show my time?

Posted: Sat Aug 09, 2003 11:27 pm
by billman
mktime should help.

Code: Select all

<?
echo date("m/d/y",mktime(date(H)-8));
?>
"-8" subtracts 8 hours from the current time, which makes it PST since there's an 8 hour time difference between PST and most of Europe.

Posted: Sun Aug 10, 2003 5:00 am
by JAM
Ass billman stated, or you could use javascript. Javascript fetches the time on the clients computer, billmans solution with a static servertime-8 so there would be no difference between .co.uk, .il, .ca and .au hosts (examples).

Posted: Sun Aug 10, 2003 2:43 pm
by m3rajk
ummm....

simple way: you know your utc offset, right?
since GMT is the basis of a UTC, create it as a UTC

for me that would be getting a print out from....

Code: Select all

<?php
$time=gmmktime("m/d/y h:i:s", (time()+(60*60*-5)));
echo "$time -05:00:00";
?>
just adjust where the 5 is to your timezone.that prints out a UTC timestamp (UTC is the time with the gmt offset) i've also seen UTC used as being synonymous with zulu (forgets about daylight savings) and rarely as being gmt (which actually changes based on daylight savnigs)

Posted: Sun Aug 10, 2003 2:49 pm
by JAM
Bare in mind: "gmmktime() - Windows does not support negative values for this function" if you have the pages located ón a windows server...

Posted: Sun Aug 10, 2003 2:53 pm
by m3rajk
purely for timezones it will never be negative.
time() is the unix timestamp......seconds since 1970 (or is it 1900?)
and you add to that, the difference betwween you and gmt in seconds.

since there's always gong to be more seconds than the offset....

Posted: Sun Aug 10, 2003 3:00 pm
by JAM
'1970-01-01 00:00:00' GMT

And yes, I know what you mean. Still, the above code will not work on a windows-box...

Posted: Sun Aug 10, 2003 3:22 pm
by m3rajk
correction: winBLOWS

if it weren't winBLOWS that code would work

Posted: Sun Aug 10, 2003 3:28 pm
by JAM
...so instead we (some of us) write to use code that works everywhere.

Posted: Sun Aug 10, 2003 4:12 pm
by m3rajk
i normally try to do that, but my dev environment is LAMP and i will find a hosting company with LAMP for mine because of the stability of linux.the thing i'm trying to do needs to be able to show members times relative to them. i store gmt_offset in hours. multiply that by 60*60 and use that to display times

Posted: Fri Dec 26, 2003 1:37 am
by onefocus99
Page Last update showing the proper time zone...

You see my server is 1 hour behind where I live
So if I want to show when my page was last updated:

$LastMod = filemtime("index.php"); //60*60=3600 or 1 hour
print(date("l F d, Y - g:i a", ($LastMod+3600) ));
which prints:
Friday December 26, 2003 - 12:31 am