How can I get the current datetime in the format "2014-04-01:08:00:00" in Node?

date, node.js

Solution

Seems that there is no good way to do it with original code unless using Regex. There are some modules such as Moment.js though.

If you are using npm:

npm install moment --save

Then in your code:

var moment = require('moment');
moment().format('yyyy-mm-dd:hh:mm:ss');

That may be much easier to understand.

Problem

I need the current system datetime in the format "yyyy-mm-dd:hh:mm:ss". https://stackoverflow.com/a/19079030/2663388 helped a lot. `new Date().toJSON()` is showing "2014-07-14T13:41:23.521Z" Can someone help me to extract "yyyy-mm-dd:hh:mm:ss" from "2014-07-14T13:41:23.521Z"?

Original source

Related problems