Using a few lines of Javascript and manipulating the date object in Javascript, we can display the current date and time clock on any web page.

Current date and time display

A sampling of the code.

var myHours = d.getHours();
var myMinutes = d.getMinutes();
var myDay = d.getDate();
var myMonth = formatMonth( d.getMonth() );
var ampm = 'AM';
var sep = '<span class="' + sepClass + '"> : </span>';
vDay.innerHTML = myMonth + ' ' + myDay;
vTime.innerHTML = myHours + sep + myMinutes + sep + d.getSeconds() + ' '  + ampm;

I hope you found this article interesting.

Share it with a friend: