zoukankan      html  css  js  c++  java
  • javascript日期时间比较(网上找的)

    <html>
    <head>
    <script type="text/javascript">
    function change()
    {
    var pattern=/^ *(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}) *$/;
    var outcome1=pattern.exec(str.value);
    var outcome2=pattern.exec(end.value);
    if (outcome1 && outcome2)
    {
    var result = compare2(outcome1[1], outcome2[1]);
    if (result == 0)
    {
    result = compare2(outcome1[2], outcome2[2]);
    if (result == 0)
    {
    result = compare2(outcome1[3], outcome2[3]);
    if (result == 0)
    {
    result = compare2(outcome1[4], outcome2[4]);
    if (result == 0)
    {
    result = compare2(outcome1[5], outcome2[5]);
    }
    }
    }
    }

    if (result == 0)
    alert("same date");
    else if (result < 0)
    alert("str < end");
    else
    alert("str > end");
    }

    function compare2(va1, va2)
    {
    if (va1 == va2)
    return 0;
    else if (va1 > va2)
    return 1;
    else
    return -1;
    }
    }
    </script>
    </head>
    <body>
    <input type="text" name="str" />
    <input type="text" name="end" />
    <input type="submit" onclick="change()" />
    </body>
    </html>

  • 相关阅读:
    Nginx配置文件详解
    Mycat概述
    日志切割之Logrotate
    js数组(二)
    js数组(一)
    sass颜色
    scss
    HTML5新属性
    HTML5新元素
    Bootstrap
  • 原文地址:https://www.cnblogs.com/lost0/p/3000437.html
Copyright © 2011-2022 走看看