Javascript returns wrong Date values (NodeJS)

后端 未结 3 600
醉话见心
醉话见心 2021-01-29 09:56

I\'m working on a NodeJS Projects and I get wrong Date values. And I don\'t get what I am doing wrong.

 var d = new Date(results[1].timestamp);
      console.log         


        
3条回答
  •  爱一瞬间的悲伤
    2021-01-29 10:09

    A few errors here:

    1. getMonth returns a 0 based month. That is May is 04.

    2. getDay returns the day of the week. I guess you want getDate

    3. the date is parsed as UTC and getHour is according to the locale. So the hour might be different from what you want (but right here it seems to be "exact", as is it's the same value than inputted).

    A tip for your next problems: Have a look at some documentation. For example the MDN.

提交回复
热议问题