Node: Different timestamp created by node.js and browser

Created on 26 Nov 2016  Â·  8Comments  Â·  Source: nodejs/node

  • Version: 7.0.0
  • Platform: mac
  • Subsystem:

new Date() function create different timestamp for nodejs runtime, the browser created is correct,what might cause this problem?

All 8 comments

Could you please give an example of Node.js and browser output, to show what you think is wrong?

2016-11-26 3 41 26

the node one is 07:xx:xx

but browser is 15:xx:xx

Those are the same date, just displayed differently. The Z in 2016-11-26T07:41:09.319Z stands for UTC+0, and you’re in UTC+8.

You can check this by using new Date().toString() and new Date().toJSON(): Both of these will return the same value in Node.js and your browser.

sorry about that,another stupid question.

@EasonWang01 Don’t worry about it, I’m glad I could help!

@addaleax: Hey there, i was wondering why the default format has been changed to an ISO string? Is there a reason?

Just curious since it caused me some trouble that i wasn't expecting :P
Thanks

@Pustur https://github.com/nodejs/node/pull/4318 was the PR that changed that, you can follow the links/discussion there. Tbh, I find it a bit weird that the ISO representation is used as the more “human-readable” format (which is what util.inspect is supposed to show), but I am pretty sure you could have endless arguments about that. :)

@EasonWang01 > sorry about that,another stupid question.

Not stupid at all! I was just thinking the world was upside down when I saw it logged to different formats! I'm happy I found your question, it was really educational for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

filipesilvaa picture filipesilvaa  Â·  3Comments

ksushilmaurya picture ksushilmaurya  Â·  3Comments

fanjunzhi picture fanjunzhi  Â·  3Comments

dfahlander picture dfahlander  Â·  3Comments

danialkhansari picture danialkhansari  Â·  3Comments