js比较日期大小

访客8年前 (2017-12-06)javaScript3583

ps: "2007-2-2" 格式的字符串不可以直接比较大小

第1种方法:

1
2
3
4
5
6
7
8
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));

第2种方法:

1
2
3
4
5
6
7
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);


本文原创,转载必追究版权。

分享给朋友:

相关文章

org.tigris.subversion.javahl.ClientException:Attempted to lock an already-locked dir

 svn更新或提交时候报错:org.tigris.subversion.javahl.ClientException:Attempted to lock an already-locke...

freemarker 判断日期变量为空处理 及InvalidReferenceException异常处理

at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:98);InvalidR...

坑爹的ShowModalDialog 后台传值解决方案

 今天遇到需要ShowModalDialog打开页面,通过acceptanceIds 参数值后台过滤出相应结果前台  var url = "loadAccept...

js/jquery 实现点击图片更换头像(图片)实例

    总之一句话, 可以先将 file类型 的input 隐藏 起来,通过 图片(头像)的onclick事件 来触发 file 的onclick事件。1.引入外部js:...

jquery 操作html元素(及CSS)

jquery 操作html元素(及CSS)

 $("li").addClass("aui-user-view-cell aui-img") ;  //给元素添加样式$('#a1...

竟然可以这样打扮!女人呆了!男人痴了!

来个轻松点的哇,惊呆了,肯定贵不了,立刻去瞅瞅...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。