SpecialSnowflake SpecialSnowflake - 3 months ago 11
Javascript Question

JS how to get date&time in specific format

I'm trying to get a log to read the current date in the following format:

YYYY-MM-DD hh:mm


Here is my current code:

var dateformat = require("dateformat");
var now = new Date();
var s = dateformat(now, "YYYY-MM-DD hh:mm");
console.log(s.toString());


The output i get is:

YYYY-06-DD 10:08


What am I doing wrong?

Answer

Read the documentation.

It should be yyyy for years, and dd for days, not uppercase.

var s = dateformat(now, "yyyy-MM-dd hh:mm");
Comments