Js date comparison functions:
Share with you a js time comparison of js functions (YYYY-MM-DD ):
Java code
1. function duibi (a, B)
2 .{
3. var arr = a. split ("-");
4. var starttime = new Date (arr [0], arr [1], arr [2]);
5. var starttimes = starttime. getTime ();
6.
7. var arrs = B. split ("-");
8. var lktime = new Date (arrs [0], arrs [1], arrs [2]);
9. var lktimes = lktime. getTime ();
10.
11. if (starttimes> = lktimes)
12 .{
13.
14. alert ('start time is later than exit time, please check ');
15. return false;
16 .}
17. else
18. return true;
19.
20 .}
Js time comparison (yyyy-mm-dd hh: mi: ss)
Java code
1. // compare the time format yyyy-mm-dd hh: mi: ss
2. function comptime (){
3. var beginTime = "00:00:00 ";
4. var endTime = "00:00:01 ";
5. var beginTimes = beginTime. substring (0, 10). split ('-');
6. var endTimes = endTime. substring (0, 10). split ('-');
7.
8. beginTime = beginTimes [1] + '-' + beginTimes [2] + '-' + beginTimes [0] + ''+ beginTime. substring (10, 19 );
9. endTime = endTimes [1] + '-' + endTimes [2] + '-' + endTimes [0] + ''+ endTime. substring (10, 19 );
10.
11. alert (beginTime + "aaa" + endTime );
12. alert (Date. parse (endTime ));
13. alert (Date. parse (beginTime ));
14. var a = (Date. parse (endTime)-Date. parse (beginTime)/3600/1000;
15. if (a <0 ){
16. alert ("Small endTime! ");
17.} else if (a> 0 ){
18. alert ("high endTime! ");
19.} else if (a = 0 ){
20. alert ("Equal time! ");
21.} else {
22. return 'exception'
23 .}
24 .}
From Chinese herbal tea