JavaScript gets the current time

Source: Internet
Author: User

//时间设置<script type="text/javascript"><!--varmyDate = newDate();    myDate.getYear();      //获取当前年份(2位)    myDate.getFullYear(); //获取完整的年份(4位,1970-????)    myDate.getMonth();      //获取当前月份(0-11,0代表1月)    myDate.getDate();      //获取当前日(1-31)    myDate.getDay();        //获取当前星期X(0-6,0代表星期天)    myDate.getTime();      //获取当前时间(从1970.1.1开始的毫秒数)    myDate.getHours();      //获取当前小时数(0-23)    myDate.getMinutes();    //获取当前分钟数(0-59)    myDate.getSeconds();    //获取当前秒数(0-59)    myDate.getMilliseconds(); //获取当前毫秒数(0-999)    myDate.toLocaleDateString();    //获取当前日期    varmytime=myDate.toLocaleTimeString();    //获取当前时间    myDate.toLocaleString( );      //获取日期与时间----如果涉及到时分秒,直接使用即可。if(mytime<"23:30:00"){    alert(mytime);}//--><pre name="code"class="java"><pre name="code" class="java"></script>//时间比较<script type="text/javascript">functioncheck(){<pre name="code"class="java"><pre name="code"class="java"><pre name="code"class="java">        varriqi1 = document.getElementById("begin_time").value;        varriqi2 = document.getElementById("end_time").value; </pre><pre name="code"class="java">        vardatePattern = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;    //alert(seller+zffs + jyzt+pid + pname);    if(riqi1 == ""&& riqi2 !=""){        if(! datePattern.test(riqi2)) {        window.alert("请填写正确的 结束日期格式");        returnfalse;        }         alert("请输入开始时间!");        returnfalse;    }    if(riqi1 != ""&& riqi2 ==""){        if (! datePattern.test(riqi1)) {        window.alert("请填写正确的 开始日期格式");        returnfalse;        }        alert("请输入结束时间!");        returnfalse;    }    if(riqi1 !=""&& riqi2 !=""){        vardatePattern = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;        if(! datePattern.test(riqi1)) {            window.alert("请填写正确的 开始日期格式");            returnfalse;        }        if(! datePattern.test(riqi2)) {            window.alert("请填写正确的 结束日期格式");            returnfalse;        }     }            vard1 = new Date(riqi1.replace(/-/g,"/"));    vard2 = newDate(riqi2.replace(/-/g,"/"));    if(Date.parse(d1) - Date.parse(d2) >= 0) {        alert("开始时间不能早于结束时间!");        returnfalse;    }</pre><pre></pre><pre></pre>}  </script> <BODY> 开始时间:<input type="text"id="begin_time"><br/>结束时间:<input type="text"id="end_time"><br/><input type="button"onclick="check()"></BODY><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre></pre></pre></pre></pre>

JavaScript gets the current time

Related Article

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.