60 lines
2.8 KiB
JavaScript
60 lines
2.8 KiB
JavaScript
/*Clock functionality. When the page is loaded it starts a one second
|
|
* long loop to update the time displayed on the page.
|
|
*/
|
|
window.onload = startInterval;
|
|
function startInterval(){
|
|
setInterval("startTime();",1000);
|
|
}
|
|
/* The function to update and format the time displayed on the page.
|
|
* The formating of Date() objects useing .toLocalString() is documented
|
|
* at the following urls:
|
|
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/DateTimeFormat
|
|
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
|
|
*/
|
|
function startTime(){
|
|
var current_time = new Date(),
|
|
our_tz = current_time.getTimezoneOffset;
|
|
document.getElementById('time_title').innerHTML = "Time is: "
|
|
+ current_time.toLocaleString('en-US',
|
|
{timeZone: current_tz,
|
|
hourCycle:'h24',
|
|
hour: '2-digit',
|
|
minute:'2-digit',
|
|
second:'2-digit',
|
|
timeZoneName:'short'});
|
|
document.getElementById('time_body').innerHTML = current_time.toLocaleString('en-EN' ,{
|
|
timeZone: current_tz,
|
|
hourCycle:'h24',
|
|
weekday:'short',
|
|
month:'short',
|
|
day:'2-digit',
|
|
year:'numeric',
|
|
hour:'2-digit',
|
|
minute:'2-digit',
|
|
second:'2-digit',});
|
|
if(display_origTZ){//Test if there is a non-null value for original_tz. If True then the part of the page this pertains to is being displayed.
|
|
document.getElementById('time_original').innerHTML = current_time.toLocaleString('en-EN' ,{
|
|
timeZone: original_tz,
|
|
hourCycle:'h24',
|
|
weekday:'short',
|
|
month:'short',
|
|
day:'2-digit',
|
|
year:'numeric',
|
|
hour:'2-digit',
|
|
minute:'2-digit',
|
|
second:'2-digit'});
|
|
}
|
|
//document.getElementById('JStz').innerHTML = current_tz;
|
|
}
|
|
|
|
function copy_timestamp() {
|
|
var copyText = document.getElementById("time_body").innerText;
|
|
var temp_element = document.createElement("textarea");
|
|
document.body.appendChild(temp_element)
|
|
temp_element.value = copyText;
|
|
temp_element.select();
|
|
temp_element.setSelectionRange(0,999);
|
|
document.execCommand("copy");
|
|
document.body.removeChild(temp_element);
|
|
}
|