How does JS date comparison work?

前端 未结 3 1114
悲&欢浪女
悲&欢浪女 2020-12-17 00:45

Let\'s assume I have a proper Date object constructed from the string: \"Tue Jan 12 21:33:28 +0000 2010\".

var dateString = \"Tue          


        
3条回答
  •  萌比男神i
    2020-12-17 01:41

    I think yes. Using if (now < twitterDate), it evaluates to if (now.valueOf(). valueOf() delivers the number of milliseconds passed since 01/01/1970 00:00:00, so the comparison of those 2 numbers is valid.

    check it like this

    var then = new Date("Tue Jan 12 21:33:28 +0000 2010")
       ,now  = new Date;
    
    console.log(then.valueOf(),'::',now.valueOf(),'::',now 1263332008000 :: 1352365105901 :: false
    

提交回复
热议问题