jquery-dateFormat icon indicating copy to clipboard operation
jquery-dateFormat copied to clipboard

Millisecond formatter do not work properly

Open GianlucaVagnoni opened this issue 6 years ago • 2 comments

If I use a formatter like this "yyyy-MM-dd HH:mm:ss.SSS" the milliseconds section (SSS) is not properly formatted. Example:

var outputDatestring = "2015-03-25T13:43:00.123+0000";
var date = new Date(outputDatestring);
console.log($.format.date(date, "yyyy-MM-dd HH:mm:ss.SSS"));

This code logs the following result (my browser is in GTM+01:00, so the hour is correct, but not the milliseconds section): 2015-03-25 14:43:00. Eu

Expected result: 2015-03-25 14:43:00.123

GianlucaVagnoni avatar Mar 05 '18 18:03 GianlucaVagnoni

Hi @GianlucaVagnoni

Unfortunately, your input format does not seem to be in the expected input list.

From where is that format coming from?

phstc avatar Aug 07 '18 12:08 phstc

Hi, That format is called ISO 8601, which is one of the most common formats used for serialization/deserialization of Date objects as a string in JSON format.

There is also another common ISO 8601 format: "2015-03-25T13:43:00.123Z"

...which is what javascript outputs with toISOString()

new Date().toISOString()
"2020-03-25T19:21:42.398Z"

Regards.

ghost avatar Mar 25 '20 19:03 ghost