当前位置:网站首页>【Js】检查Date对象是否为Invalid Date
【Js】检查Date对象是否为Invalid Date
2022-07-23 14:39:00 【前端不加班】
使用Date的getTime()方法,Invalid Date对象返回的是一个NaN,可以利用这点来检查Date对象是否为Invalid Date。
function isValidDate(date) {
return date instanceof Date && !isNaN(date.getTime())
}
// 也可以
// function isValidDate(date) {
// return date instanceof Date && !isNaN(date.valueOf())
// }
var date = new Date("dream");
console.log('结果',isValidDate(date)); //false
var date2 = new Date("2019-053");
console.log('结果',isValidDate(date2)); //false
var date3 = new Date("2019-05-09");
console.log('结果',isValidDate(date3)); //true
边栏推荐
- How to refine the operation of small program mall?
- Software configuration | Anaconda download, installation, environment configuration and uninstall
- PPPoE协议讲解以及拨号过程Wireshark抓包解析
- Investment and finance report this week: Web3 game bear market attracts gold
- Compressed storage of arrays and special matrices
- Explain SQL optimization in detail
- 日志瘦身骚操作:从5G优化到1G!
- 程序环境和预处理
- Pymoo学习 (2):带约束的双目标优化问题
- 软件质量体系之思
猜你喜欢

通过SSH方式访问内网RDS+mysql

程序员最想干的三件事 |漫画

排序-介绍,代码思路,使用建议,代码实现-1

SQL报错盲注详解

通用分页实现

MySQL:不是MySQL问题的MySQL问题

12 pictures +6k figure ZGC garbage collector and tuning skills

Pyinstaller+installforge multi file project software packaging

What about the new retail e-commerce platform? Can we realize the digital transformation of traditional retail enterprises?

USB通信协议深入理解
随机推荐
转账业务追加日志(事务的传播行为).
SQL报错盲注详解
图的先深搜索、图的先广搜索 (三种方法实现)
深度学习学习记录-优化器的学习率的更新
Fundamentals of C language -- 2-5 points of knowledge about pointers and functions
12 pictures +6k figure ZGC garbage collector and tuning skills
PPPoE协议讲解以及拨号过程Wireshark抓包解析
Detailed explanation of SQL error reporting and blind annotation
七月集训(第23天) —— 字典树
使用 PreparedStatement 的 JDBC 程序示例
quota命令详细拓展使用方法,RHEL 7中quota命令搭载方法!磁盘容量配额!
Could not load dynamic library ‘cudnn64_8.dll‘; dlerror: cudnn64_8.dll not found
Three things programmers want to do most | comics
OpenCV求两个区域的交集
PMP practice once a day | don't get lost in the exam -7.23
What about the reason why GOM and GEE set up a black screen and the fact that individual equipment maps are not displayed?
"Now, the number of codes has expanded to astronomical level"
Function secondary development / plug-in development of JMeter (detailed version)
【mysql集群故障恢复】
First deep search and first wide search of graph (realized by three methods)