在JavaScript中确定日期是今天的最好方法是什么? [英] What is the best way to determine if a date is today in JavaScript?
本文介绍了在JavaScript中确定日期是今天的最好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我关心的是比较日期对象,因为可能有一个不同于另一个的时间,但是今天的任何时间应该返回 true
。
解决方案
您可以使用 toDateString
var d = new Date()
var bool =(d.toDateString() === otherDate.toDateString());
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 as one might have a different time than another but any time on today's date should return true
.
解决方案
You could use toDateString
:
var d = new Date()
var bool = (d.toDateString() === otherDate.toDateString());
这篇关于在JavaScript中确定日期是今天的最好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文