Date.now().toISOString() throwing error “not a function”

前端 未结 1 1135
我在风中等你
我在风中等你 2020-12-30 18:20

I am running Node v6.4.0 on Windows 10. In one of my Javascript files I am trying to get an ISO date string from the Date object:

let timestamp = Date.now()         


        
相关标签:
1条回答
  • 2020-12-30 19:02

    Date.now() returns a number which represents the number of milliseconds elapsed since the UNIX epoch. The toISOString method cannot be called on a number, but only on a Date object, like this:

    var now = new Date();
    var isoString = now.toISOString();
    

    Or in one single line:

    new Date().toISOString()
    
    0 讨论(0)
提交回复
热议问题