How to display current date and time using javascript

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.

Let me know if you have any questions or comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Endorsed by these folks ...

Femy is great and very easy to work with. She’s capable, responsive and produces good work.

Brennan Hom Technical Program Manager, Solutionset