江西网站搜索引擎优化,wordpress 自定义样式,搜索引擎营销实训报告,四川房产信息网官网js检验一个字符串是否是正确时间格式的工具方法
(() {/*** 检验字符串是否为时间格式* param {String} date 需要检验的时间格式* returns true 为时间格式#xff0c;false 为非时间格式*/const isTimaFormat (date) {if(!date) return false;try{const tempTime …js检验一个字符串是否是正确时间格式的工具方法
(() {/*** 检验字符串是否为时间格式* param {String} date 需要检验的时间格式* returns true 为时间格式false 为非时间格式*/const isTimaFormat (date) {if(!date) return false;try{const tempTime new Date(date)if(tempTime.toString() Invalid Date || isNaN(tempTime.getDay())){throw new Error(参数: ${date} 非法无法转化为Date类型)}return true}catch(e){console.error(e)return false}}console.log(是否是时间格式, isTimaFormat(201314)) // 输出 trueconsole.log(是否是时间格式, isTimaFormat(dasdsa)) // 输出 false, 并控制台给出错误信息
})()运行结果如下如: