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).

Answer from chbrown on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
JavaScript Date objects represent a single moment in time in a platform-independent format. Date objects encapsulate an integral number that represents milliseconds since the midnight at the beginning of January 1, 1970, UTC (the epoch).
🌐
W3Schools
w3schools.com › js › js_dates.asp
W3Schools.com
February 4, 2026 - Date objects are static.
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!
🌐
Bitstack
blog.bitsrc.io › how-to-slash-through-node-js-date-comparison-pitfalls-43d7939b0d06
How to Slash Through Node.js Date Comparison Pitfalls | by Dureksha Wasala | Medium
November 12, 2024 - When it comes to handling date comparisons with Node.js, you might assume that going for an actual date is easier than this 😅. This post provides valuable tips and tricks for mastering date comparisons, enabling you to handle complex tasks such as calendar scheduling and filtering appointments with ease.
Find elsewhere
🌐
date-fns
date-fns.org
date-fns - modern JavaScript date utility library
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
🌐
Bugfender
bugfender.com › blog › javascript-date-and-time
The Definitive Guide to JavaScript Date and Time | Bugfender
February 18, 2025 - Explore the JavaScript Date object in our detailed guide. Learn to compute and format dates, and delve into the APIs essential for modern app development.
🌐
npm
npmjs.com › package › date-fns
date-fns - npm
Modern JavaScript date utility library. Latest version: 4.1.0, last published: 2 years ago. Start using date-fns in your project by running `npm i date-fns`. There are 25112 other projects in the npm registry using date-fns.
      » npm install date-fns
    
Published   Sep 17, 2024
Version   4.1.0
🌐
DEV Community
dev.to › srashtigupta › mastering-date-time-manipulation-in-javascript-nodejs-mh
Mastering Date & Time Manipulation in JavaScript (Node.js) - DEV Community
March 12, 2025 - In this article, we’ll explore several JavaScript Date methods that can help you handle timestamps, compare expiration times, and work with dates effectively.
🌐
GitHub
github.com › datejs › Datejs
GitHub - datejs/Datejs: A JavaScript Date and Time Library · GitHub
Datejs is an open source JavaScript Date library for parsing, formatting and processing.
Starred by 1.9K users
Forked by 473 users
Languages   JavaScript 97.7% | HTML 1.8% | CSS 0.5%
🌐
GeeksforGeeks
geeksforgeeks.org › node.js › node-js-date-format-api
Node.js Date.format() API - GeeksforGeeks
January 8, 2025 - NodeJS HTTP2 · Last Updated : 8 Jan, 2025 · The date-and-time.Date.format() is a minimalist collection of functions for manipulating JS date and time module which is used to format the date according to a certain pattern. Required Module: Install the module by npm or used it locally.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Temporal
Temporal - JavaScript | MDN
December 8, 2025 - The Temporal object enables date and time management in various scenarios, including built-in time zone and calendar representation, wall-clock time conversions, arithmetics, formatting, and more. It is designed as a full replacement for the Date object.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-format-a-date-with-javascript-date-formatting-in-js
How to Format a Date with JavaScript – Date Formatting in JS
November 7, 2024 - In this article, we'll explore various techniques to format dates in JavaScript, enabling you to present dates in your desired format for your application.
🌐
Medium
medium.com › diving-into-development › building-a-simple-api-with-node-js-javascript-dates-b9a615816b6d
Building a simple API With Node.js & JavaScript Dates | by Shaina Karasin | Diving into Development | Medium
May 31, 2017 - To solve requirements #4–5, we’ll build our outputs as JavaScript objects in the required formats. To access the pieces and formats of the time that we need, we’ll use JavaScript’s built-in Date methods on our date object.
🌐
Node.js
nodejs.org › en › about › previous-releases
Node.js — Node.js Releases
Node.js® is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts.
🌐
NestJS
docs.nestjs.com › techniques › task-scheduling
Documentation | NestJS - A progressive Node.js framework
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
Create a Date object with the time equal to number of milliseconds (1/1000 of a second) passed after the Jan 1st of 1970 UTC+0.