What is the best way to determine if a date is today in JavaScript?

后端 未结 5 1480
北荒
北荒 2020-12-05 23:32

I have a date object in JavaScript and I want to figure out if that date is today. What is the fastest way of doing this?

My concern was around comparing date object

5条回答
  •  情话喂你
    2020-12-06 00:04

    var someDate = new Date("6 Dec 2011").toDateString();
    var today = new Date().toDateString();
    var datesAreSame = (today === someDate);
    

提交回复
热议问题