How to Get the Current Date in Javascript?


There are several ways to get the current date in Javascript:

  1. Using the Date Object:

    var today = new Date();

    The new Date() function returns the current date and time.

  2. Using the method:

    var today =;

    The method returns the current timestamp in milliseconds since January 1, 1970.

  3. Using the new Intl.DateTimeFormat() method:

    var today = new Intl.DateTimeFormat().format(new Date());

    The Intl.DateTimeFormat() method formats the date according to the user's locale.

  4. Using the Moment.js library:

    var today = moment().format('YYYY-MM-DD');

    The Moment.js library provides a powerful API for handling date and time in Javascript. Here, we're using the format() method to specify the output format of the date.

Latest Questions

javascript How to Check if a Javascript Array Includes a Given Value? javascript How to Completely Uninstall Nodejs, and Reinstall From Scratch on Mac OS X? javascript How to Map Values of a Javascript Object to a New Object Using a Function?