NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Local Time script

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 12-15-2005, 02:25 AM THREAD STARTER               #1 (permalink)
Account Suspended
Join Date: Oct 2005
Location: India
Posts: 633
blackwizard is a jewel in the roughblackwizard is a jewel in the roughblackwizard is a jewel in the rough
 



Local Time script


Demo:

Server Time: 1:24:55 AM (Thurs)
Paris: 10:24:55 AM (Thurs)
New York: 4:24:55 AM (Thurs)
Tokyo: 6:24:55 PM (Thurs)

Directions: Developer's View

Step 1: Insert the below script into the HEAD section of your page:

Select All

Step 2: Inside your <BODY>, define a DIV or SPAN tag with a unique ID that will contain the local time, then invoke "showLocalTime()" to populate it:

Current Server Time:<span id="timecontainer"></span>

<script type="text/javascript">
new showLocalTime("timecontainer", "server-ssi", 0, "short")
</script>

Here's an explanation of the 4 parameters of showLocalTime():

1. ContainerID (string): The ID of the DIV or span that will house the local time.
2. Servermode (string): Valid values are either "server-php", "server-asp", or "server-ssi", to indicate this page as either of type, PHP, ASP, or SSI.
3. LocaltimeoffsetMinutes (integer): The offset in minutes of the local time you wish to display, from the server time. For example, if your server time is currently 9:30 AM and you know the desired local time is 11:30AM, the offset is 120, or 2 hours then.
4. Display Format (string): valid values are either "short" or "long". The latter will cause the local date to be displayed along with the time.

For the "servermode" parameter, it must be set to either "server-php", "server-asp", or "server-ssi", depending on whether your page is php, asp, or ssi enabled, respectively. This script will NOT work on 100% static pages, such as plain .html.

That's it. Read on for additional helpful information.
How to calculate the "LocaltimeoffsetMinutes" value for the desired world location

For the "LocaltimeoffsetMinutes" parameter of showLocalTime(), set it to the offset in minutes between the desired local time and the server time. You can calculate this offset easily, by doing this:

1) Display the server time on your page first, by setting "LocaltimeoffsetMinutes" to 0:

<script type="text/javascript">
new showLocalTime("timecontainer", "server-ssi", 0, "short")
????: NamePros.com http://www.namepros.com/programming/148267-local-time-script.html
</script>

Lets say the time you see on your page is 3:20:45 PM. This is your server's current time.

2) Look up the current time of the location you wish to display, such as New York. Lets say it turns out to be 5:20:54 PM. You now know that "LocaltimeoffsetMinutes" should be 120, or 2 hours separating the two dates. As another example, lets say the desired local time you wish to display is LA, with the current LA time being 2:20:54 PM. The "LocaltimeoffsetMinutes" in this case should be -60 then, or 1 hour separating the two dates, but in the opposite direction (server time is greater than LA time).

3) With "LocaltimeoffsetMinutes" determined, you can now go ahead and display the desired local time. For example:

Current LA Time:<span id="timecontainer"></span>

<script type="text/javascript">
new showLocalTime("timecontainer", "server-ssi", -60, "short")
</script>

That wasn't too difficult was it?
More Information

Before you run off, just a couple more points that are mention worthy:

1) Displaying multiple dates- The object oriented design of this script means you can invoke it multiple times to display multiple local times on the same page! Here's an example:

Current Server Time:<span id="timecontainer"></span><br />
Current LA Time:<span id="timecontainer2"></span><br />
Current New York Time:<span id="timecontainer3"></span><br />

<script type="text/javascript">
new showLocalTime("timecontainer", "server-asp", 0, "short")
????: NamePros.com http://www.namepros.com/showthread.php?t=148267
new showLocalTime("timecontainer2", "server-asp", -60, "short")
new showLocalTime("timecontainer3", "server-asp", 120, "short")
</script>

1) Watch out for daylight savings time- Depending on where your server is located and/or the local time you wish to display, you may need to adjust "LocaltimeoffsetMinutes" twice yearly to account for Day Light Savings time. If the script is suddenly displaying an incorrect local time, you know that you probably need to re-perform the two steps required to get "LocaltimeoffsetMinutes" again.
blackwizard is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Real Time Adsense Tracking Script ethiccash Scripts For Sale 0 12-11-2005 01:42 AM
60.000 Templates, scripts, fonts, banners etc. $9.95 atkims Web Development Wanted 19 11-16-2004 10:48 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 05:08 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger