Forum Moderators: coopster

Message Too Old, No Replies

Just need to know

If this script actually does work in different time zones

         

adni18

4:00 pm on Dec 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi. I am just starting tp experiment with PHP, and I made a little script that should show you the time and date in your time zone. It works for me, but does it work for other time zones?

<?php
$new_U=date("U")-0*3600;
$days=array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
print $days[date("w", $new_U)] . ", " . date("F d, Y ", $new_U);
$regHrs=(date("O", $new_U)/100+5)*-1;
print date(" g ", $new_U)+$regHrs . ":" . date("i A", $new_U);
?>

[edited by: jatar_k at 5:13 pm (utc) on Dec. 19, 2004]
[edit reason] changed formatting [/edit]

benevolent001

4:08 pm on Dec 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry if its wrong but
Dont you think...we can test it by changing our own computer time zone etc.. and see if its working?

Although its working fine for me
Great work!

Kysmiley

5:45 pm on Dec 19, 2004 (gmt 0)

10+ Year Member



works great for me. I was looking for something like that my host is central i'm eastern and the date() shows central. Now to figure out how to put it in the middle of an html line i will test it with <? echo ('time.php')?> or somthing liike that. great work though
Pat

Kysmiley

5:59 pm on Dec 19, 2004 (gmt 0)

10+ Year Member



worked perfect I did not or could not figure out the echo to work so i used the include ('time.php') in the middle of a line where I want the time and date to display and it worked perfect
Thanks a bunch

Kysmiley

6:02 pm on Dec 19, 2004 (gmt 0)

10+ Year Member



sorry spoke too soon. It is 1 pm and the time shows 1 am so that part is picking up wrong
but is great. Let mme know how to changer this part when u can

Pat

Kysmiley

6:16 pm on Dec 19, 2004 (gmt 0)

10+ Year Member



Hmmm, i just changed time zones on my pc and it still displayed eastern time. Host is centeral I changed to pacific, and it displayed eastern. As for the displaying 12 hours off, you have it set to a 24 hr clock with am and pm. that should be changed to either a 12 hr clock with both or a 24 hr clock with out the A,
Pat

Kysmiley

6:56 pm on Dec 19, 2004 (gmt 0)

10+ Year Member



problem lies in this line
$regHrs=(date("O", $new_U)/100+5)*-1;
it changes any time to gmt-500 which is eastern only. I would think it would need to catch the server time the client time and then convert from one to the other. So u already know your server timezone, it does not change of should not. next time is to figure out how to grab the client time zone from their ip or pc and convert nfrom there

adni18

8:35 pm on Dec 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But how do I do that? The IP? I always thought "O" was the user's timezone...?

jollymcfats

8:50 pm on Dec 19, 2004 (gmt 0)

10+ Year Member



The client's timezone isn't sent as part of the HTTP request.

You can collect the user's UTC offset client-side in Javascript, however the Date object doesn't tell you if Daylight Saving Time is in currently in effect; all you get is raw, current offset seconds. If you just want to display the current time that's fine, but if you're converting arbitrary dates and times into the client's timezone you'll have headaches.