JS Date manipulation function

Source: Internet
Author: User

1 /**2 * Gets the local format string for the current time3 * @returns {String}4  */5DATE.PROTOTYPE.GETLOCALETIMESTR =function(){6     return  This. tolocaletimestring ();7 };8 9 /**Ten * Gets the local format string for the current time, leaving only the number part One * @returns {String} A  */ -DATE.PROTOTYPE.GETPURELOCALETIMESTR =function(){ -     return  This. tolocaletimestring (). Replace (/^\d*/, "); the }; -  - /** - * Get a few seconds at a time + * @param gap number - * @returns {Date} +  */ ADATE.PROTOTYPE.GETGAPSSECONDLOCALETIMESTR =function(GAP) { at     //return new Date (THIS-GAP *); - } -  - /** - * Get a few minutes apart - * @param gap number in * @returns {Date} -  */ toDATE.PROTOTYPE.GETGAPSMINUTELOCALETIMESTR =function(GAP) { +     //return new Date (THIS-GAP *); - }; the /** * * Get the date seven days ago $ * @returns {String}Panax Notoginseng  */ -Date.prototype.getPreSevenDate =function(){ the      This. SetDate ( This. GetDate ()-7); +     return  This. Format ("Yyyy-mm-dd hh:mm:ss"); A }; the /** + * Get dates for a day - * @param {number} day days before/after date $ * @returns {String} $  */ -Date.prototype.getSomeDayDate =function(day) { -      This. SetDate ( This. GetDate () +Day ); the     return  This. Format ("Yyyy-mm-dd hh:mm:ss"); - };Wuyi /** the * Gets the current time (call method: New Date (). Format ("Yyyy-mm-dd hh:mm:ss")) - * @param fmt Wu * @returns {string}/2016-01-01 00:00:00/ -  */ AboutDate.prototype.Format =function(FMT) { $     varn \ { -"m+": This. GetMonth () + 1, -"D+": This. GetDate (), -"H +": This. GetHours (), A"m+": This. getminutes (), +"S+": This. getseconds (), the"q+": Math.floor (( This. GetMonth () + 3)/3), -"S": This. Getmilliseconds () $     }; the     if(/(y+)/. Test (FMT)) theFMT = Fmt.replace (regexp.$1, ( This. getFullYear () + "") the. substr (4-regexp.$1. length)); the      for(varKincho) -         if(NewRegExp ("(" + K + ")"). Test (FMT)) inFMT = Fmt.replace (regexp.$1, (regexp.$1.length = = 1)?(O[k]) the: (("XX" + o[k]). substr ("" +O[k] )); the     returnFMT; About }; the  the /** the * Date Operation related methods +  */ - varMydateutil = { the         /**Bayi * Set Date (0 for today, 1 for yesterday, etc.) the * @param adddaycount the * @returns {string}/2016-01-01/ -          */ -GETDATESTR:function(adddaycount) { the         varDD =NewDate (); theDd.setdate (Dd.getdate () +adddaycount);//get the date adddaycount days the         vary =dd.getfullyear (); the         varm = Dd.getmonth () +1;//Gets the date of the current month -         if(m<10){ them = ' 0 ' +m; the         } the         varD =dd.getdate ();94         if(d<10){ theD = ' 0 ' +D; the         } the         98         returny+ "-" +m+ "-" +D; About     }, -     /**101 * Find another date based on one date102 * @param {} theday:2016-04-20103 * @param {} adddaycount: (-1 is the day before, 1 is the latter, 0 is unchanged, etc.)104 * @return {String} the      */106Finddaybyday:function(theday,adddaycount) {107         varFormatday =NewDate (theday);108Formatday.setdate (Formatday.getdate () +adddaycount);//get the date adddaycount days109         vary =formatday.getfullyear (); the         varm = Formatday.getmonth () +1;//Gets the date of the current month111         if(m<10){ them = ' 0 ' +m;113         } the         varD =formatday.getdate (); the         if(d<10){ theD = ' 0 ' +D;117         }118         119         returny+ "-" +m+ "-" +D; -     },121     /**122 * Returns the number of milliseconds from January 1, 1970 (can be used to compare the time size)123 * @param {} Date format is: Yyyy-mm-dd124      */ theFormattimesfromdate:function(Date) {126         vararr = Date.split ("-");127         varNewdate =NewDate (arr[0],arr[1],arr[2]); -         varResultdate =newdate.gettime ();129         returnresultdate; the     }131}

JS Date manipulation function

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.