Get current Date in javascript

current date in javascript

Get current Date in javascript

How to get current date in javascript?

Date() is a feature of javascript. Check the full date feature here.

var d = new Date();

var month = d.getMonth()+1;
var day = d.getDate();

var output = d.getFullYear() + '/' + (month<10 ? '0' : '') + month + '/' +
    (day<10 ? '0' : '') + day;

Date objects are created with the new Date() constructor.

By default, JavaScript will use the browser’s time zone and display a date as a full text string:

for eg:- Tue Dec 29 2020 23:07:27 GMT+0530 (India Standard Time)

d.getMonth() returns current month as a number from 0-11 that’s why +1 added to month.

For more date functions click here.

2 thoughts on “Get current Date in javascript

Leave a Reply

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

Back To Top