User:Arichnad/utc clock.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
 function zero(num) {return num<10 ? "0"+num : num;}
 var textNode;
 function putDateInHeading() {
 	textNode = document.createTextNode("");
 	
 	var element = document.createElement('li');
 	element.appendChild(textNode);
 	element.id = "pt-datetime";
 	
 	var list = document.getElementById('p-personal').getElementsByTagName('ul')[0];
 	list.appendChild(element);
 }
 function updateTime() {
 	var date = new Date();
 	var str = date.getUTCDate() + " " + zero(date.getUTCHours()) + ":" + zero(date.getUTCMinutes());
 	textNode.nodeValue = str;
 	var waitSeconds = 60-date.getUTCSeconds()+1;
 	window.setTimeout(updateTime, waitSeconds*1000);
 }
 function setup() {
 	putDateInHeading();
 	updateTime();
 }

$(setup);