Local Time script
Note (Nov 22nd, 16'): Script rewritten to use moment.js library for built in way to get time zone offsets.
Finally, this script can be called multiple times on the same page to display simultaneously the local times of different places. Cool!
Step 1: Insert the below script into the HEAD section of your page:
The code references two external libraries, which you should download below:
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:
Here's an explanation of the 3 parameters of
- ContainerID (string): The ID of the DIV or span that will house the local time.
- Time Zone Id (string): A valid time zone identifier string to specify the time zone of the target location you wish to display the time for, such as "Asia/Jakarta".
Time Format (string): The format of the final displayed date and time.
Pass in the desired "tokens" as described on Moment.js's
Formatting Section, such as:
ddd, hA": Sun, 2AM
hh:mm:ss A (ddd)": 02:22:54 AM (Sun)
dddd, MMMM Do YYYY, h:mm:ss a": Sunday, November 19th 2016, 02:22:54 pm
And that's it! Regardless of the final format you've chosen, the displayed time will be updated every second, live.