Date.js简单的方法来确定是否在解析中指定时间

date.js simple way to determine if time specified in parse

本文关键字:定时间 是否 简单 js 方法 Date      更新时间:2023-09-26

使用date.js's Date.parse 确定用户输入字符串(例如'oct 31 12am' vs 'oct 31')是否包含时间值的最简单方法是什么,即是否明确指定了时间

使用正则表达式检查用户是否输入了am或pm,如果没有,则给他们一个消息,说明必须包含它

<script type="text/javascript">
var str= $("#date_input").val; 
var patt1=/am|pm/gi;
if (!str.match(patt1)){
     $("#message").text("you must include a time in either 'am' or 'pm' format");
}
</script>