JS time Format--time plus and minus implementation

Source: Internet
Author: User

How to format time:

1Date.prototype.Format =function(FMT) {//Author:meizz2             varo = {3"m+": This. GetMonth () + 1,//Month4"D+": This. GetDate (),//Day5"H +": This. GetHours (),//hours6"m+": This. getminutes (),//points7"S+": This. getseconds (),//seconds8"q+": Math.floor (( This. GetMonth () + 3)/3),//Quarterly9"S": This. Getmilliseconds ()//millisecondsTen             }; One             if(/(y+)/.test (FMT)) FMT = Fmt.replace (regexp.$1, ( This. getFullYear () + ""). substr (4-regexp.$1. length)); A              for(varKincho) -                 if(NewRegExp ("(" + K + ")"). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.length = = 1)? (O[k]): (("XX" + o[k]). substr ("" +O[k] )); -             returnFMT; the}
1 <script type= "Text/javascript" >2   var mydate=New  Date (); 3   document.write ("Current Time:" +mydate+ "<br>"); 4   Mydate.settime (Mydate.gettime () + * + *); 5   document.write ("Delay One hour:" + mydate); 6 </script>
1 functiondatetest ()2         {3             varD =NewDate ("2016-01-01 16:00:01");4             //alert (d.getdate () + "--" + d.getday ());5             //alert (D.gettime ());6             //set the time plus one hours7             varEnd =NewDate (D.gettime () + 60 * 60 * 1000);8 alert (end);9Alert (end. Format ("Yyyy-mm-dd hh:mm:ss"));Ten}

JS time Format--time plus and minus implementation

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.