JS on the operation of the time

Source: Internet
Author: User

JS Time Operation Daquan

1. Get the start and end of each month.

2. Get the start and end of each quarter.

3, get the current quarter.

4. Convert date to string (supports various formats)

...

5, not to be continued to continue to add

String.prototype.padingstar=function(totallength,padingstr= "") {            if(Totallength <= This. Length) {                return  This; }            varPadlength = Totallength- This. Length; if(Padlength <=padingstr.length) {returnPadingstr.substring (0, Padlength) + This; } Else {                varLen = padlength/padingstr.length, n = 1,str= ";  while(n<Len) {STR+=Padingstr; N++; }                returnSTR + padingstr.substring (0, Padlength-(n-1) * padingstr.length) + This; }} String.prototype.padingEnd=function(Totallength, padingstr= "") {            //After the beginning of the completion of the complete            if(Totallength <= This. Length) {                return  This; }            varPadlength = Totallength- This. Length; if(Padlength <=padingstr.length) {returnPadingstr.substring (0, Padlength) + This; } Else {                varLen = padlength/padingstr.length, n = 0,str= ";  while(n<Len) {STR+=Padingstr; N++; }                return  This+ padingstr.substring (0, Padlength-(n-1) * padingstr.length) +str; }        }        //get the start of the current monthDate.prototype.starofmonth=function() {            return NewDate ( This. getFullYear (), This. GetMonth (), 1, 00, 00, 00); }        //get the end of the current monthDate.prototype.endofmonth=function() {            return NewDate ( This. getFullYear (), This. GetMonth () + 1, 0, 23, 59, 59); }        //gets the start time of the current quarterDate.prototype.starofquarter=function() {            return NewDate ( This. getFullYear (), ( This. Getquarter ()-1) * 3, 01, 00, 00, 00); }        //Gets the end time of the current quarterDate.prototype.endofquarter=function() {            return NewDate ( This. getFullYear (), This. Getquarter () * 3-1, 31, 23, 59, 59); }        //get the quarter for the current timeDate.prototype.getquarter=function() {            returnMath.ceil (( This. GetMonth () + 1)/3); }        //get the start of the year that corresponds to the current timeDate.prototype.starofyear=function() {            return NewDate ( This. getFullYear (), 01, 01, 00, 00, 00); }         //Gets the end of the current time corresponding yearDate.prototype.endofyear=function() {            return NewDate ( This. getFullYear (), 12, 31, 23, 59, 59); }        //format the time as a stringDate.prototype.toDateString =function(format) {if(typeof(format) = = "Undefined") {                return  This. toString (); }            //Perhaps my first thought was that            if(/y{4}/. Test (format)) {Format= Format.replace (/yyyy/g, This. getFullYear ()); }            if(/y{2}/. Test (format)) {Format= Format.replace (/y{2}/g, This. getFullYear (). toString (). substr (2)); }            if(/m{2}/. Test (format)) {Format= Format.replace (/mm/, This. GetMonth (). toString (). Padingstar (2,0)); }            if(/dd/. Test (format)) {Format= Format.replace (/dd/, This. GetDate (). toString (). Padingstar (2, ' 0 ')); }            if(/hh/. Test (format)) {Format= Format.replace (/hh/g, This. GetHours (). toString (). Padingstar (2, ' 0 ')); }            if(/hh/. Test (format)) {Format= Format.replace (/hh/g, (Hour < hour:hour-12). ToString (). Padingstar (2, ' 0 ')); }            if(/mm/. Test (format)) {Format= Format.replace (/mm/g, This. getminutes (). toString (). Padstart (2, ' 0 ')); }            if(/ss/. Test (format)) {Format= Format.replace (/ss/g, This. getseconds (). toString (). Padstart (2, ' 0 ')); }            returnformat; }                //get two time-separated daysdate.prototype.betweendays=function(date) {varDayspan = (Date.parse ( This)-Date.parse (Date))/86400000; returnDayspan; }

GitHub Address: Https://github.com/gdoujkzz/JsDate.git

JS on the operation of the time

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.