<%@ Page Language="C#" Debug="true"%> Code Samples- International Time Zone Clocks
Microsoft Office FrontPage 2003      
Developer's Toolkit
Resources | Links | Search
  extend design code  
             
  New Features
 
Microsoft® Windows® SharePoint Services
 
Microsoft® Office SharePoint Portal Server
 
Microsoft Office System
 
.NET Framework
 
 
Real world scenarios that fully expose great new functionality in FrontPage 2003 and Windows SharePoint Services.
 
 
  financial planning finance  
  sales & marketing sales & marketing  
  human resources human resources  
   
  FrontPage Customization Kit > Resources > Code Library

International Time Zone Clocks Documentation

Contents

Example

Download this sample

 

Summary

The International Time Zone Clocks display the current date and time for most time zones. The time displayed can be updated as frequently as you desire, and can take whatever format you choose.

An International Time Zone Clock is created in javascript with the TZClock object. Unlike some other samples, this object is not displayed by called a Render method. Instead, call the Attach method for each HTML element whose inner text (or value) you would like periodically replaced with the current time.
 

Usage

There is one required file: clock.js. Include it on your page with a link like this:

	<script type="text/javascript" src="clock.js"></script>

If you would like to use time zone codes, you will also need to include timezones.js (an 11KB file) like this:

	<script type="text/javascript" src="timezones.js"></script>

Before including the next script block, you should have all the HTML for your page. You can use any HTML element that provides an innerText property, or the HTML input (type="text") element. For each element that you want to use as a clock, you should also make sure that it has a unique ID attribute, like this:

	<div id="PacStd">time will be shown here</div>

If you have any visual formatting that you want to apply to the clock, this is the place to do it. For instance, to rewrite the previous line to display red text instead, do this:

	<div id="PacStd" style="color:red;">time will be shown here</div>

If you use the HTML input element, make sure that it is inside a FORM element.

You will need another script block to create an instance of the TZClock object, like this:

	<script type="text/javascript">
		var TZClockSample = new TZClock();
	</script>

Next, you will need to attach HTML elements to your new TZClock object, like this:

	<script type="text/javascript">
		TZClockSample.Attach("PacStd", "-08:00");
	</script>

Note that you can combine SCRIPT blocks together. They are shown separately here for clarity.

Finally, you need to start getting the clocks updated, like this:

	<script type="text/javascript">
		TZClockSample.Start(1);
	</script>

This will begin updating the clocks as soon as the page is viewed in the browser.

If you decide to attach the TZClock to a TD element of a table, make sure that you don't try to Attach the TZClock to the TD element until after the closing TABLE tag (</table>) of the TABLE element. See Using Table Elements for more information.
 

Reference

There is only one object for this sample. The TZClock object provides all needed functionality.

TZClock
Properties
Property Type Description
GetFormattedTime function This optional property gets or sets a function reference to a function that accepts a javascript Date object and returns a javascript String object in the desired format. If you do not set this property, it will use a default formatting function.
The default time formatting function is called TZClock_DefaultGetFormattedTime. It merely called the Date object's toLocaleString method to return a string formatted with the browser's regional settings for a long date (includes both date and time).

The function signature looks like this:

function callbackFormattedTime(Date)
{
return String;
}
Depending on your application, it may be important to include the date as well as the time.

The GetFormattedTime property is demonstrated on the example page.
 
Methods
Methods Parameter Description
Attach   Adds an HTML element or INPUT element to a list of elements which are updated with the current date and time when the TZClock is started.
Because the time zone offset is associated with the attached element, you can attach the TZClock to more than element on a page, each with a different time zone offset.
sElementID String that specifies the ID of the HTML element into which the TZClock should insert the current time. Acceptable elements include any HTML element with a writeable innerText property, or an HTML input text type element.

These are the HTML elements in Internet Explorer 6.0 that have a writeable innerText property:

A
ACRONYM
ADDRESS
B
BDO
BIG
BLOCKQUOTE
BODY
BUTTON
CAPTION
CENTER
CITE
CODE
CUSTOM
DD
DEL
DFN
DIR
DIV
EM
FIELDSET
FONT
FORM
hn
I
IFRAME
INS
KBD
LABEL
LEGEND
LI
LISTING
MAP
MARQUEE
MENU
nextID
NOBR
OL
OPTION
P
PLAINTEXT
PRE
Q
RT
RUBY
S
SAMP
SCRIPT
SELECT
SMALL
SPAN
STRIKE
STRONG
SUB
SUP
TD
TEXTAREA
TH
TITLE
TT
U
UL
VAR
XMP

The DIV, SPAN, and TD elements are probably the most commonly used elements for this.

sTimeZoneOffset String that specifies the offset of the time zone from Coordinated Universal Time (UTC), also called Greenwich Mean Time (GMT).
This parameter must be provided in a specific format. The format is:

{+|-}hh[:]mm
{+|-} is either the plus (+) or minus (-) sign, indicating an eastward or westward offset, respectively, from the prime meridian, which is the location for UTC. Time zones in the US are westward of the prime meridian, so US time zones have a negative offset, indicated with a minus (-) sign.

hh is the hours offset from UTC, with a leading zero if needed to make a two-digit number.

[:] is an optional colon to separate the hours from the minutes.

mm is the minutes (combined with the hours) offset from UTC, with a leading zero if needed to make a two-digit number.

These are valid sTimeZoneOffset arguments:

+1000
+04:30
-03:45
-0800

These are not valid sTimeZoneOffset arguments:

+10
+04.30
-03:75
-800
Start   Begins a periodic update of all of the HTML elements that have been attached to the TZClock object with the Attach method.
nInterval Optional. Integer that indicates the length of time between updates in seconds (not milliseconds). The default value is 1 second.
Stop   Halts the periodic update of the HTML elements that were being updated.

Remarks

Daylight Saving Time

The rules for the beginning and end of Daylight Saving Time are not only complicated to determine within the United States (not all states or counties recognize Daylight Saving Time), they are very difficult to apply within any degree of certainty to other nations that recognize Daylight Saving Time (or Summer Time). Some nations determine the beginning and end of Daylight Saving Time based on political decree, rather than any consistent rules, changing them from year to year.

For this reason, this sample makes no attempt to determine whether the time currently being displayed falls within Daylight Saving Time. This is left as an exercise for the reader. However, for those time zones that have a Daylight Saving Time or Summer Time code, the time zone code lookups will return the number of minutes to apply for Daylight Saving Time. Thus, if you choose to write code to support it, it should be simple to allow the person browsing your site to select whether they are in an area that recognizes Daylight Saving Time, and whether they are currently in Daylight Saving Time.

Time Zone Offsets

To assist in determine the proper offset for a time zone, which you need when calling the Attach method, an optional file, timezones.js, includes a table with offsets for many time zones around the world, identified with a unique code. These codes are arbitrary, as there are no standards with which to conform. However, by examining the comments in the source code, you should be able to easily locate any time zone, or the closest match.

The function TZClock_GetUTCOffsetFromTimeZoneCode accepts a String argument with one of the time zone codes from the array _sTZCodes, located in timezones.js, and returns a string with the time zone offset that is suitable for using in the Attach method.
 

Customization

This section contains suggestions for how you can customize the script to suit your particular needs. The script provided does not already contain the necessary code to implement these suggestions. The suggestions merely provide guidance on how you might apply your own customizations.

Daylight Saving Time

As mentioned earlier, you may want to attempt to detect whether the user is currently in Daylight Saving Time. In some parts of the world (most of the US, for example), the rules for Daylight Saving Time remain fairly consistent. If you know that the reader is a user in the United States, and is in one of the states that recognizes Daylight Saving Time statewide, you can alternately look up the time zone offset for Daylight Saving Time from the TZClock_GetUTCOffsetFromTimeZoneCode function. These time zones are commonly identified with a comment that contains the word "Daylight" or "Summer" in the file timezones.js.

Note that if you add an odd number of news items to the NewsScroller, the first and last news items you add will both have the same CSS style. You can avoid this either by always adding only an even number of news items, or by adding a test in NewsScroller_ScrollNews function. This function has a commented section that is responsible for moving an element that has just scrolled off the top of the display block to the bottom of the news items. If (ns.itemCount % 1 == 1) then there are an odd number of news items in the NewsScroller, and you should always toggle the attribute of the news item element elmItem, and then set its className property accordingly.

^ Back to top