javascript Date().getTime() is not a function

前端 未结 3 1731
独厮守ぢ
独厮守ぢ 2020-12-09 14:47

I\'m trying to compare some Dates in javascript.

For some reason, I\'m getting \"Tue May 01 2012 16:43:03 GMT+0900 (JST) has no method \'getTime\'\"

Of cours

相关标签:
3条回答
  • 2020-12-09 15:08

    Try using new keyword to instantiate a new object so instead of this

    var now = Date();
    

    try this

    var now = new Date();
    
    0 讨论(0)
  • 2020-12-09 15:13

    This will make 'now' as variable type as date:

    var now = new Date();
    

    This will get you time from 'now':

    new Date(now).getTime();
    
    0 讨论(0)
  • 2020-12-09 15:25

    You need to use the new operator to create a Date object.

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