Date(); Wrong Time Zone

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Shiro
Forum Newbie
Posts: 12
Joined: Sat Aug 09, 2003 7:08 am

Date(); Wrong Time Zone

Post 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?
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post 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.
Shiro
Forum Newbie
Posts: 12
Joined: Sat Aug 09, 2003 7:08 am

Yeah

Post by Shiro »

Yeah its In Europe so X( is there any way i can get it to show my time?
User avatar
billman
Forum Newbie
Posts: 9
Joined: Sun Oct 27, 2002 5:06 pm

Post 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.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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).
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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)
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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...
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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....
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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...
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

correction: winBLOWS

if it weren't winBLOWS that code would work
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

...so instead we (some of us) write to use code that works everywhere.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
onefocus99
Forum Newbie
Posts: 16
Joined: Tue Oct 07, 2003 11:09 pm
Location: Hamilton Ont., Montreal, Chibougamau,... PQ, Victoria BC, now Alberta Canada

Post 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
Post Reply