当前位置:网站首页>在js中正则表达式验证小时分钟,将输入的字符串转换为对应的小时和分钟
在js中正则表达式验证小时分钟,将输入的字符串转换为对应的小时和分钟
2022-06-24 06:41:00 【做笔记用】
1、预备知识
splict()方法

Date()的相关方法


setHours()的用法

2、在js中的代码片段
//验证小时和分钟
var reDateTime = /^(?:(?:[0-2][0-3])|(?:[0-1][0-9])):[0-5][0-9]$/;
var isDateTime = reDateTime.test('18:00');
console.log(isDateTime)
var startTime = "09:00";
var endTime = "18:00";
var t1 = new Date();
let start = startTime.split(":") ;
t1.setHours(start[0],start[1],0);
console.log("开始时间:"+t1)
var t2 = new Date();
let end = endTime.split(":");
t2.setHours(end[0],end[1],0);
console.log("结束时间:"+t2)
if(t1.getTime() > t2.getTime()){
console.log("错误");
}else if(t1.getTime() == t2.getTime()){
console.log("相等")
}else{
console.log("正确")
}
3、测试结果

边栏推荐
- LuChen technology was invited to join NVIDIA startup acceleration program
- Database stored procedure begin end
- You have a chance, here is a stage
- 记录--关于virtual studio2017添加报表控件的方法--Reportview控件
- 0 foundation a literature club low code development member management applet (III)
- Le système de surveillance du nuage hertzbeat v1.1.0 a été publié, une commande pour démarrer le voyage de surveillance!
- mysql中的 ON UPDATE CURRENT_TIMESTAMP
- Spark累加器和广播变量
- JSON formatting method advantages of JSON over XML
- Go breakpoint continuation
猜你喜欢

Challenges brought by maker education to teacher development

Maui uses Masa blazor component library

Rockscache schematic diagram of cache operation

FreeRTOS MPU makes the system more robust!

leetcode:1856. Maximum value of minimum product of subarray

Localized operation on cloud, the sea going experience of kilimall, the largest e-commerce platform in East Africa

Leetcode概率题面试突击系列11~15

Record -- about the method of adding report control to virtual studio2017 -- reportview control

2022蓝队HW初级面试题总结

Functions in setinterval cannot have parentheses
随机推荐
Functions in setinterval cannot have parentheses
Go operation SQLite code error
If you want to learn programming well, don't recite the code!
Jumping game ii[greedy practice]
Spark accumulators and broadcast variables
JSON formatting method advantages of JSON over XML
0 foundation a literature club low code development member management applet (II)
What is the main function of cloud disk? How to restore deleted pictures
System design: partition or data partition
Another double win! Tencent's three security achievements were selected into the 2021 wechat independent innovation achievements recommendation manual
Rockscache schematic diagram of cache operation
Mysql开启BINLOG
Spark project Packaging Optimization Practice
What is the role of domain name websites? How to query domain name websites
JSON online parsing and the structure of JSON
JVM调试工具-Arthas
2022蓝队HW初级面试题总结
The cloud monitoring system hertzbeat V1.1.0 is released, and a command starts the monitoring journey!
leetcode:84. The largest rectangle in the histogram
树莓派4B开发板入门