//适合格式(0000-00-00)       
//日期比较
function dateCompare(startdata, enddata) {
var arr = startdata.split("-");
var starttime = new Date(arr[], arr[], arr[]);
var starttimes = starttime.getTime(); var arrs = enddata.split("-");
var lktime = new Date(arrs[], arrs[], arrs[]);
var lktimes = lktime.getTime(); if (starttimes > lktimes) {
return false;
}
else
return true;
}
//调用

var startdata = $("#ipt_startdate").datebox('getValue');
var enddata = $("#ipt_enddate").datebox('getValue');
if (!dateCompare(startdata, enddata)) {
return $.messager.alert('提示', '您输入的时间有误!', 'warning');
}

JS时间比较

//比较日期大小
function compareDate(checkStartDate, checkEndDate) {
var arys1 = new Array();
var arys2 = new Array();
if (checkStartDate != null && checkEndDate != null) {
arys1 = checkStartDate.split('-');
var sdate = new Date(arys1[0], parseInt(arys1[1] - 1), arys1[2]);
arys2 = checkEndDate.split('-');
var edate = new Date(arys2[0], parseInt(arys2[1] - 1), arys2[2]);
if (sdate > edate) {
// alert("日期开始时间大于结束时间");
return true;
} else {
//alert("通过");
return false;
}
}
} //判断日期,时间大小
function compareTime(startDate, endDate) {
if (startDate.length > 0 && endDate.length > 0) {
var startDateTemp = startDate.split(" ");
var endDateTemp = endDate.split(" "); var arrStartDate = startDateTemp[0].split("-");
var arrEndDate = endDateTemp[0].split("-"); var arrStartTime = startDateTemp[1].split(":");
var arrEndTime = endDateTemp[1].split(":"); var allStartDate = new Date(arrStartDate[0], arrStartDate[1], arrStartDate[2], arrStartTime[0], arrStartTime[1], arrStartTime[2]);
var allEndDate = new Date(arrEndDate[0], arrEndDate[1], arrEndDate[2], arrEndTime[0], arrEndTime[1], arrEndTime[2]); if (allStartDate.getTime() >= allEndDate.getTime()) {
// alert("startTime不能大于endTime,不能通过");
return true;
} else {
//alert("startTime小于endTime,所以通过了");
return false;
}
} else {
alert("时间不能为空");
return true;
}
}
//比较日期,时间大小
function compareDateTime(startDate, endDate) {
if (startDate.indexOf(" ") != -1 && endDate.indexOf(" ") != -1) {
//包含时间,日期
return compareTime(startDate, endDate);
} else {
//不包含时间,只包含日期
return compareDate(startDate, endDate);
}
}

js日期比较(yyyy-mm-dd)

 function duibi(a, b) {
var arr = a.split("-");
var starttime = new Date(arr[0], arr[1], arr[2]);
var starttimes = starttime.getTime(); var arrs = b.split("-");
var lktime = new Date(arrs[0], arrs[1], arrs[2]);
var lktimes = lktime.getTime(); if (starttimes >= lktimes) { alert('开始时间大于离开时间,请检查');
return false;
}
else
return true; } js时间比较(yyyy-mm-dd hh:mi:ss) function comptime() {
var beginTime = "2009-09-21 00:00:00";
var endTime = "2009-09-21 00:00:01";
var beginTimes = beginTime.substring(0, 10).split('-');
var endTimes = endTime.substring(0, 10).split('-'); beginTime = beginTimes[1] + '-' + beginTimes[2] + '-' + beginTimes[0] + ' ' + beginTime.substring(10, 19);
endTime = endTimes[1] + '-' + endTimes[2] + '-' + endTimes[0] + ' ' + endTime.substring(10, 19); alert(beginTime + "aaa" + endTime);
alert(Date.parse(endTime));
alert(Date.parse(beginTime));
var a = (Date.parse(endTime) - Date.parse(beginTime)) / 3600 / 1000;
if (a < 0) {
alert("endTime小!");
} else if (a > 0) {
alert("endTime大!");
} else if (a == 0) {
alert("时间相等!");
} else {
return 'exception'
}
}

js两个日期对比大小的更多相关文章

  1. js 比较两个日期的大小的例子

    例子,直接比较大小即可 代码如下 复制代码 <script>var st="2009-10-20 14:38:40"var et="2009-10-20 15 ...

  2. iOS编程中比较两个日期的大小

    转自:http://www.myext.cn/other/a_30922.html 比较日期大小是任何编程语言都会经常遇到的问题,再iOS编程中,通常用NSDate对象来存储一个时间(包括日期和时间. ...

  3. C#代码中如何比较两个日期的大小?

    C#中比较两个日期大小的方法 /// <summary> /// 比较两个日期大小 /// </summary> /// <param name="dateSt ...

  4. java中比较两个日期的大小

    String beginTime=new String("2014-08-15 10:22:22"); String endTime=new String("2014-0 ...

  5. C#比较两个日期的大小 .net

    using System;using System.Collections; public class MyClass{public static void Main(){DateTime dt1 = ...

  6. 之前有面试到两个日期的大小比较方式,现在整理一下几种方法。   例子:   String beginTime=new String("2017-06-09 10:22:22");     String endTime=new String("2017-05-08 11:22:22");  1  直接用Date自带方法before()和after()比较 SimpleDateFormat d

    各种数据类型(日期/时间.integer.floating point和numeric)转换成格式化的字符串以及反过来从格式化的字符串转换成指定的数据类型.下面列出了这些函数,它们都遵循一个公共的调用 ...

  7. js-比较两个日期的大小

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...

  8. Java比较两个日期的大小

    public static String getComparedSBQDate(String yxqq,String starttime){ String str = starttime; Simpl ...

  9. js 两个日期比较相差多少天

    var day1 = new Date("2017-9-17"); var day2 = new Date("2017-10-18"); console.log ...

随机推荐

  1. 【LeetCode】Path Sum ---------LeetCode java 小结

    Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that addi ...

  2. HDU 3746 Cyclic Nacklace KMP

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3746 KMP算法—— AC代码: #include <iostream> #include ...

  3. 获取WebView里的网页文本内容

    获取WebView里的网页文本内容,能够採用例如以下方法: public class ComJSInterface { public void loadHtmlContent(String conte ...

  4. 用composer安装 Laravel | Laravel需要的环境配置

    一:安装 参考网站 http://v4.golaravel.com/docs/4.2/installation 1.先确保安装好了PHP,和服务器环境 2.然后下载composer可执行文件到当前目录 ...

  5. 【xcode】错误之Could not launch "" failed to get the task for process

    http://blog.csdn.net/teng_ontheway/article/details/8467932 在Xcode下编译工程正常,在模拟器下运行正常,最后在真机上运行的时候出现了如下错 ...

  6. HBase 几点思考

    1. http://blog.csdn.net/yueyedeai/article/details/14648067 2. http://blog.csdn.net/pirateleo/article ...

  7. STL--stack/queue的使用方法

    stack(栈)和queue(队列)也是在程序设计中经常会用到的数据容器,STL为我们提供了方便的stack(栈)的queue(队列)的实现. 准确地说,STL中的stack和queue不同于vect ...

  8. 包子IT面试培训

    包子IT面试培训 IT 面试不再怕,包子帮你圆个梦!

  9. apache .htaccess文件详解和配置技巧总结

    一..htaccess的基本作用 .htaccess是一个纯文本文件,它里面存放着Apache服务器配置相关的指令.       .htaccess主要的作用有:URL重写.自定义错误页面.MIME类 ...

  10. [计算机网络] vsftpd的安装与使用

    简单介绍: vsftpd是一个能够执行在类UNIX操作系统上的FTPserver软件,它能够执行在Linux.BSD.Solaris.HP-UX等系统上. 1 vsftpd的安装 在ubuntu系统上 ...