Just leverage the built-in toISOString method that brings your date to the ISO 8601 format:

let yourDate = new Date()
yourDate.toISOString().split('T')[0]

Where yourDate is your date object.

Edit: @exbuddha wrote this to handle time zone in the comments:

const offset = yourDate.getTimezoneOffset()
yourDate = new Date(yourDate.getTime() - (offset*60*1000))
return yourDate.toISOString().split('T')[0]
Answer from Darth Egregious on Stack Overflow
🌐
Medium
medium.com › @techsolutionstuff › node-js-get-current-date-and-time-example-e7893d95c174
Node JS Get Current Date And Time Example | by Techsolutionstuff | Medium
September 29, 2023 - It is loaded by default and requires no import of modules. Also, you can get the current date, month, year, hour, minutes & seconds in node js. In node.js you can get the current date-time formatted as YYYY-MM-DD hh:mm:ss, YYYY-MM-DD, DD-MM-YYYY, etc.
🌐
GeeksforGeeks
geeksforgeeks.org › node.js › how-to-format-the-current-date-in-mm-dd-yyyy-hhmmss-format-using-node-js
How to format the current date in MM/DD/YYYY HH:MM:SS format using Node? - GeeksforGeeks
July 23, 2025 - const date = new Date(); // Function ... input; }; // Data about date const format = { dd: formatData(date.getDate()), mm: formatData(date.getMonth() + 1), yyyy: date.getFullYear(), HH: formatData(date.getHours()), hh: formatData...
🌐
UsefulAngle
usefulangle.com › post › 187 › nodejs-get-date-time
Getting Date and Time in Node.js
// current timestamp in milliseconds ... = date_ob.getFullYear(); // prints date & time in YYYY-MM-DD format console.log(year + "-" + month + "-" + date);...
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-basic-exercise-3.php
JavaScript: Display the current date in various format - w3resource
This JavaScript program retrieves ... dd-mm-yyyy, dd/mm/yyyy). It uses the Date object to get the current day, month, and year, and then adds leading zeros if necessary to ensure proper formatting....
🌐
W3Schools
w3schools.com › js › js_date_formats.asp
JavaScript Date Formats
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... The ISO format follows a strict standard in JavaScript. The other formats are not so well defined and might be browser specific. Independent of input format, JavaScript will (by default) output dates in full text string format: ISO 8601 is the international standard for the representation of dates and times. The ISO 8601 syntax (YYYY-MM-DD) is also the preferred JavaScript date format:
🌐
Futurestud.io
futurestud.io › tutorials › how-to-format-a-date-yyyy-mm-dd-in-javascript-or-node-js
How to Format a Date YYYY-MM-DD in JavaScript or Node.js
/** * Returns the `date` formatted in YYYY-MM-DD. * * @param {Date} date * * @returns {String} */ function format (date) { if (!(date instanceof Date)) { throw new Error('Invalid "date" argument.
🌐
DEV Community
dev.to › techsolutionstuff › how-to-get-current-date-and-time-in-nodejs-4jm
How To Get Current Date And Time In Node.js - DEV Community
July 29, 2022 - In Node.js date and time are handled with the Javascript Date object. It is loaded by default and requires no import of modules. Also, you can get the current date, month, year, hour, minutes & seconds in Node.js. In Node.js you can get the current date-time formatted as YYYY-MM-DD hh:mm:ss, YYYY-MM-DD, DD-MM-YYYY, etc.
Find elsewhere
🌐
Squash
squash.io › how-to-format-javascript-date-as-yyyy-mm-dd
How to Format JavaScript Dates as YYYY-MM-DD
Save the above code in a JavaScript file, for example, formatDate.js, and run it using Node.js: ... This will output the current date in the YYYY MM DD format.
Top answer
1 of 16
731

If you're using Node.js, you're sure to have EcmaScript 5, and so Date has a toISOString method. You're asking for a slight modification of ISO8601:

new Date().toISOString()
> '2012-11-04T14:51:06.157Z'

So just cut a few things out, and you're set:

new Date().toISOString().
  replace(/T/, ' ').      // replace T with a space
  replace(/\..+/, '')     // delete the dot and everything after
> '2012-11-04 14:55:45'

Or, in one line: new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '')

ISO8601 is necessarily UTC (also indicated by the trailing Z on the first result), so you get UTC by default (always a good thing).

2 of 16
135

UPDATE 2021-10-06: Added Day.js and remove spurious edit by @ashleedawg
UPDATE 2021-04-07: Luxon added by @Tampa.
UPDATE 2021-02-28: It should now be noted that Moment.js is no longer being actively developed. It won't disappear in a hurry because it is embedded in so many other things. The website has some recommendations for alternatives and an explanation of why.
UPDATE 2017-03-29: Added date-fns, some notes on Moment and Datejs
UPDATE 2016-09-14: Added SugarJS which seems to have some excellent date/time functions.


OK, since no one has actually provided an actual answer, here is mine.

A library is certainly the best bet for handling dates and times in a standard way. There are lots of edge cases in date/time calculations so it is useful to be able to hand-off the development to a library.

Here is a list of the main Node compatible time formatting libraries:

  • Day.js [added 2021-10-06] "Fast 2kB alternative to Moment.js with the same modern API"
  • Luxon [added 2017-03-29, thanks to Tampa] "A powerful, modern, and friendly wrapper for JavaScript dates and times." - MomentJS rebuilt from the ground up with immutable types, chaining and much more.
  • Moment.js [thanks to Mustafa] "A lightweight (4.3k) javascript date library for parsing, manipulating, and formatting dates" - Includes internationalization, calculations and relative date formats - Update 2017-03-29: Not quite so light-weight any more but still the most comprehensive solution, especially if you need timezone support. - Update 2021-02-28: No longer in active development.
  • date-fns [added 2017-03-29, thanks to Fractalf] Small, fast, works with standard JS date objects. Great alternative to Moment if you don't need timezone support.
  • SugarJS - A general helper library adding much needed features to JavaScripts built-in object types. Includes some excellent looking date/time capabilities.
  • strftime - Just what it says, nice and simple
  • dateutil - This is the one I used to use before MomentJS
  • node-formatdate
  • TimeTraveller - "Time Traveller provides a set of utility methods to deal with dates. From adding and subtracting, to formatting. Time Traveller only extends date objects that it creates, without polluting the global namespace."
  • Tempus [thanks to Dan D] - UPDATE: this can also be used with Node and deployed with npm, see the docs

There are also non-Node libraries:

  • Datejs [thanks to Peter Olson] - not packaged in npm or GitHub so not quite so easy to use with Node - not really recommended as not updated since 2007!
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
Returns a string representing the Date using toISOString(). Intended to be implicitly called by JSON.stringify().
🌐
npm
npmjs.com › package › date-and-time
date-and-time - npm
const { format } = require('date-and-time'); format(new Date(), 'ddd, MMM DD YYYY'); // => Wed, Jul 09 2025
      » npm install date-and-time
    
Published   Mar 07, 2026
Version   4.3.1
Author   KNOWLEDGECODE
🌐
freeCodeCamp
freecodecamp.org › news › javascript-date-now-how-to-get-the-current-date-in-javascript
JavaScript Date Now – How to Get the Current Date in JavaScript
June 15, 2020 - You need to replace the strings "mm", "dd", "yy" with the respective month, day and year values from the format string passed in the argument. To do that you can use the replace() method like shown below: ... But this will lead to a lot of method ...
🌐
Sling Academy
slingacademy.com › article › javascript-get-and-format-current-date-time
JavaScript: Get current date time in yyyy/MM/dd HH:mm:ss format - Sling Academy
This concise article shows you how to get the current date and time in Javascript in yyyy/MM/dd HH:mm:ss format. We’ll write code from scratch without using any third-party libraries. In the example below, we will create a new...
🌐
Day.js
day.js.org › docs › en › display › format
Format · Day.js
dayjs().format() // current date in ISO8601, without fraction seconds e.g. '2020-04-02T08:02:17-05:00' dayjs('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]') // 'YYYYescape 2019-01-25T00:00:00-02:00Z' dayjs('2019-01-25').format('DD/MM/YYYY') // '25/01/2019'
🌐
TutorialsTeacher
tutorialsteacher.com › javascript › javascript-date
JavaScript Date: Create, Convert, Compare Dates in JavaScript
Learn how to work with the Dates in JavaScript. JavaScript provides Date object to work with date & time including days, months, years, hours, minutes, seconds and milliseconds.