PHP code letting you display the visitor's localtime on your generated pages.
Download
- localtime.php
- Localtime library code
- localtime.tgz
- Localtime library code and two example pages
- localtime.zip
- Localtime library code and two example pages
Changelog
5 Mar 2005
- Added two example pages that use the localtime library
- Autodetecting current hostname
30 Jul 2002
Bookmark/Search this post with:
Comments
Displaying Local Time
Hi
I am completely new to this and don't have a clue where to start.
What I need is some kind of script php or otherwise, to display a local time clock for any specific city anywhere in the world.
e.g. I am looking at a page and can see a clock displaying New York's local time, I will then go to another page and see a clock displaying London's local time.
How do I go about making this scipt? Any help will be greatly appreciated!
Thanks
Bruno
Multiple times
You need to add another parameter or use an on-page method to determine the right time zone.
localtime.php
Hello Martin,
I placed localtime.php into the same directory as my webpages. I also added the php/javascript part into my index.html page (into the body). Nothing happens.
What am I doing wrong?
Thanks!
Local time display - getting the code to work and one hour out
Hey I'm a newby too, but i think you need to have index.php as your filename (and be on a php enabled server of course). Having said that, I have those conditions met and still havent gotten the code working on my site. It sort of works on my local machine in a php test page, but the time is one hour wrong. possibly because i'm in a timezone that stays constant year round (Sask)? I also got some weird warnings about 'cannot send session cookie' and 'Cannot send session cache limiter' but that likely has to do with it being on my local machine...
i sure thought this would be simpler, just take the time from the local machine's own clock... wouldnt that make it easy!
RJ
Re: Localtime
Carmen, you need PHP support.
If you have PHP support, just rename index.html to index.php and then it should run.
To see the effect you need to at least follow one link (forms don't work).
offset in seconds.
Hello.
I found this page because I am having problems with cookies not expiring in time in IE. IE cookies are expiring later because the server and local time are in different time zones. To fix this problem I wanted to set the cookies based on the user's local time. I am not interested in displaying the date/time. I just want to know the offset in seconds so I can use it to set cookies like this.
setcookie("cookie",1,time() + $_SESSION['GMT_offset'] + 120 )
That is going to set the cookie to expire in 2 minutes in local time.
Is that line correct? Since I need to include your code in every page I don't know if it is going to slow down my page execution time.
parse error
i copied the whole code, and save it as localtime.php, but when i open it
an error like Parse error: parse error, unexpected '{' in /home/gwconnect/localtime.php on line 16
appears...what would be the problem
TY
Thanks
Cool - thank you.
works great
good idea. works great.
Error on Function
Im a newbie and I included the file in my php pages, but I get parse error on line 16. What could be the problem?
Thanks.
Date
How To display the date on the web page, because, from java script i have, i can't change the script to php script
Local time adjust globally if .htaccess
I am a new PHP-user. I have problems with date-time scripts at my server. Is there any way to set (like .htaccess file) all my php scripts to adjust automatically with local time, other than server time?
Quite a while ago I wanted to find out the timezone(s) of my visitor(s) and display various dates and times accordingly. However, I wanted to have the session variable set immediately and automatically, not having to wait for the user to click on something (such as in Martin's page1 / page2 example downloadable here). So I looked at some other similar pages on this topic (e.g. http://www.webmasterworld.com/forum88/5685.htm) and I came up with (or I should say adopted) the idea of forcing a javascript to run "onLoad" of the first page, this script detemines the offset and then triggers a php script which sets it in a session variable.
function setGMToffset(func) {
var now = new Date();
var tzo = now.getTimezoneOffset();
document.write('');
//setoffset.php takes the offset and puts it into a session variable to be accessed by any php that wants it
document.open(); //this has to be here for mozilla / opera
document.close(); //this maybe has to be here too, anyway it don't hurt
}
I did this a maybe a year ago, but it was only working in limited browsers (not Opera or Firefox). It was until I added the document.open(); and document.close(); lines today that I totally solved the problem and it now works in all browsers. (Also, it seems crucial for some reason that document.open(). comes AFTER document.write(); (not before). Quite honestly I don't really know why this is necessary (other than the example here: http://www.mozilla.org/docs/dom/domref/dom_doc_ref51.html) but it works and that's good enough for me at the moment .