JavaScript – How to get current Date

To get current date. Use new Date() to generate a new Date object containing the current date and time.

var today   = new Date();
var dd       = today.getDate();
var mm       = today.getMonth()+1; //January is 0!
var yyyy     = today.getFullYear();

if(dd < 10) {
    dd = '0'+dd

if(mm < 10) {
    mm = '0'+mm

today = dd+ '/' + mm + '/' + yyyy;

This will give you today’s date in the format of dd/mm/yyyy. Simply change today = dd+'/'+ mm+'/'+ yyyy; to whatever format you wish.

Author: Wu Chia Chong

My main areas of interest are software architectures and software design methods, patterns, and new trends in software development.