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;
console.log(output);

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.

Related Posts

disable mouse right click

Disable Mouse Right click

How to disable mouse right click using javascript? Most of the time we may need to disable mouse right click in our website in order to reduce…

Random Alpha-Numeric String By Javascrip

Generate Random alpha-numeric string by javascript – here is 1 simple methods

How to Generate random alpha-numeric string using javascript Generating random alpha-numeric string by javascript or jQuery can be achieved very easily because it requires some built in…

This Post Has 2 Comments

Leave a Reply

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