Home > Software design >  difference between Date() in nodejs and in the browser
difference between Date() in nodejs and in the browser

Time:08-29

Why is it when i call Date() in nodejs i get the following weird output that i cant understand:

var d = new Date();
console.log(d);

output in nodejs: 2022-08-28T14:47:09.877Z

output in browser: Sun Aug 28 2022 15:48:25 GMT 0100 (Central European Standard Time)

1- What is T14:47:09.877Z in the case of nodejs output?

2- What is the rational to provide a different implementation of date object in nodejs?

CodePudding user response:

It's ISO 8601

This is a pretty common date format, you can get it using toISOString

EcmaScript doesn't specify how the date should look after using toString hence the difference. ISO format is much more useful for backend operations.

  • Related