[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 12-15-2005, 01:25 AM   #1 (permalink)
Account Suspended
 
Join Date: Oct 2005
Location: India
Posts: 636
15.35 NP$ (Donate)

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")
</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")
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 11:21 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85