SpecialSnowflake SpecialSnowflake - 1 year ago 97
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?

Answer Source

Read the documentation.

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

var s = dateformat(now, "yyyy-MM-dd hh:mm");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download