确认变量是否是日期
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript Date 对象</h1>
- <p>这个“自制的” isDate() 函数在日期上使用时返回 true:</p>
- <p id="demo"></p>
- <script>
- var myDate = new Date();
- document.getElementById("demo").innerHTML = isDate(myDate);
- function isDate(myDate) {
- return myDate.constructor.toString().indexOf("Date") > -1;
- }
- </script>
- </body>
- </html>