SpecialSnowflake SpecialSnowflake - 6 months ago 29
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");

The output i get is:

YYYY-06-DD 10:08

What am I doing wrong?


Read the documentation.

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

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