JS time comparison

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.