我想知道是否有任何方法可以检查对象是否是 JavaScript 中的 Date。IsType 为 Date 返回对象,这对于本场景来说是不够的。有什么想法吗?谢谢!
Use instanceof
(myvar instanceof Date) // returns true or false
Object.prototype.toString.call(obj) === "[object Date]" will work in every case, and obj instanceof Date will only work in date objects from the same view instance (window).
Object.prototype.toString.call(obj) === "[object Date]"
obj instanceof Date
window
if(obj && obj.getUTCDay){ // I'll treat it like a Date }
if (parseDate("datestring"))