js-比较两个日期的大小
生活随笔
收集整理的這篇文章主要介紹了
js-比较两个日期的大小
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
第一種方法:
function CompareDate(d1,d2) {return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/")))); }var current_time = "2007-2-2 7:30"; var stop_time = "2007-1-31 8:30"; alert(CompareDate(current_time,stop_time));第二種方法:
var curTime = new Date(); //2把字符串格式轉換為日期類 var startTime = new Date(Date.parse(kc.begintime)); var endTime = new Date(Date.parse(kc.endtime));//3進行比較 return (curTime>=startTime && curTime<=endTime);
轉載于:https://www.cnblogs.com/onesmail/p/5522488.html
總結
以上是生活随笔為你收集整理的js-比较两个日期的大小的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CentOS 7 使用iptables防
- 下一篇: JS实现大整数乘法(性能优化、正负整数)