Displaying Author Local Time
3. Configure the Script
Join the Discussion
More of this Feature
The script that displays the time actually runs on your visitor's computer and relys on their having their timezone and local time set correctly in order to calculate what the time is at your location.
You will need to update a number of fields at the top of the script to refer to your location and timezone and if your location uses daylight saving time you will need to update one line of the script twice a year to convert your time to and from daylight saving time. I have not attempted to automate this as some countries vary their start and end dates from year to year.
- dst indicates whether you are on daylight savings time or not, update this to 1 when you are on daylight saving time and back to 0 when daylight saving time ends.
- loc is the name of the place where you are located. (In my case 'Sydney, Australia')
- mtz is your local time zone relative to Universal Coordinated Time (which was previously called Greenwich mean Time). This is the number of hours ahead of UTC that your local time is so if local time is behind UTC then the value should be negative. (In my case this is set to 10 because Sydney is 10 hours ahead)
- stdz is your local identifier for standard time. (in my case 'AEST')
- dayz is your local identifier for daylight savings time. (in my case 'ADST')
The remainder of the script obtains the current UTC time and day using the current time and timezone from the visitor's computer and then adjusts it for the timezone that you have specified in order to display the time at your location.
The script works fine as is if you live somewhere that doesn't use daylight saving time (you can just set dst to zero and ignore dayz in that case). The script as written requires manual adjustment twice a year if you have daylight saving in order to update the dst value as you go on and off of daylight saving time.
You can (if you wish) add extra code to set the value for dst automatically based on the dates that Daylight Saving Time starts and finishes.
Note that the script and the descriptions of the functions that it contains are rewritten from the ">Ask Felgall" website with the permission of the copyright owner.

