blackwizard
Account Closed
- Impact
- 12
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.
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.








