Bilal Alam
Bilal Alam

Reputation: 894

Why does Date().toLocaleString returns different value in nodejs than browser?

While executing new Date().toLocaleString() on chrome returns "5/2/2019, 11:55:00 AM",

executing the same code on nodejs returns

"5/2/2019, 11:55:00", without AM/PM

I need to have a 12-hours format date with AM/PM mentioned in nodejs similar to what is returned in browser.

Am i missing something and this is the expected behavior?

Upvotes: 2

Views: 1214

Answers (1)

apple apple
apple apple

Reputation: 10591

it's implementation dependent, i.e. different implementation can return different string format.


20.3.4.41 Date.prototype.toString()

The following steps are performed:

... Else, Let tv be this time value. Return ToDateString(tv).

20.3.4.41.1 Runtime Semantics: ToDateString(tv)

The following steps are performed:

  1. Assert: Type(tv) is Number.

  2. If tv is NaN, return "Invalid Date".

  3. Return an implementation-dependent String value that represents tv as a date and time in the current time zone using a convenient, human-readable form.


It seems like there would be a standard format in the future, though.

Upvotes: 2

Related Questions