tinydate.js[v0.2] Optimized call mode

Source: Internet
Author: User

Problems that exist
Call method is too cumbersome, some functions need to be instantiated before the call, this and the convenience of the original intention does not meet, so make the following adjustments.
Tinydate.js v0.2

Date.prototype.format = function(FMT){    varO= {        "m+":  This.GetMonth()+ 1,                 //month        "d+":  This.getDate(),                    //day        "H +":  This.getHours(),                   //hour        "m+":  This.getminutes(),                 //min        "S+":  This.getseconds(),                 //Sec        "q+": Math. Floor(( This.GetMonth()+ 3) /3), //Quarterly        "f+":  This.getmilliseconds()//MS    };    if(/(y+)/.Test(FMT)){Fmt= FMT.Replace(RegExp. $,( This.getFullYear()+ "").substr(4 - RegExp. $.length));    }     for(varKinchO{        if(New RegExp("(" +K+ ")").Test(FMT)){Fmt= FMT.Replace(RegExp. $,(RegExp. $.length == 1)?(O[k]): (("XX" +O[k]).substr(("" +O[k]).length)));        }    }    returnFmt;}//Current full timeDate.$nowDate = New Date().format("Yyyy-mm-dd HH:mm:ss.ffff");//Get the current time in a custom formatDate.$now = function(FMT){    return New Date().format(FMT);}//Calculate time differenceDate.diff = function(sdate,EDate){    if(eDate== undefined ||EDate== NULL) eDate= New Date();    varStime= sdate.GetTime();    varETime= eDate.GetTime();    varDifftime=ETime-Stime;    varTimeSpan= New TimeSpan(Difftime);    returnTimeSpan;}//Add yearDate.prototype.Addyear = function(number){     This.setFullYear( This.getFullYear()+Number;}//Add monthDate.prototype.Addmonth = function(number){     This.setmonth( This.GetMonth()+Number;}//Add DayDate.prototype.adddate = function(number){     This.setDate( This.getDate()+Number;}//Add hoursDate.prototype.addHours = function(number){     This.sethours( This.getHours()+Number;}//Add pointsDate.prototype.addminutes = function(number){     This.setminutes( This.getminutes()+Number;}//Add secondsDate.prototype.addseconds = function(number){     This.setseconds( This.getseconds()+Number;}//Add millisecondsDate.prototype.Addmilliseconds = function(number){     This.setmilliseconds( This.getmilliseconds()+Number;}//Get the date of the first day of the yearDate.prototype.Getthefirstdateoftheyear = function(date){    varYear,Month=0,Day=1;    if(Date== undefined ||Date== NULL){Year=  This.getFullYear();    }    Else {Year= Date.getFullYear();    }    return New Date(Year,Month,Day;}//Get the date of the last day of the yearDate.prototype.Getthelastdateoftheyear = function(date){    varYear,Month=  One,Day=  to;    if(Date== undefined ||Date== NULL){Year=  This.getFullYear();    }    Else {Year= Date.getFullYear();    }    return New Date(Year,Month,Day;}//Format current date as time limit objectDate.prototype.TimeSpan = function(){    return New TimeSpan( This);}//Time limit objectfunction TimeSpan(){    varO= New Object();    o. Year = 0;//year    o.Month = 0;//month    o. Day = 0;//day    o.hours = 0;//Time    o.minutes = 0;//min    o.seconds = 0;//Sec    o.milliseconds = 0;//MS    o.Totalyear = 0.00;//From the time origin of the year    o.Totalmonth = 0.00;//From the time origin to the present month    o.Totalday = 0.00;//From the time origin to the present day    o.totalHours = 0.00;//From the time origin to the present hour    o.totalminutes = 0.00;//From the origin of time to the present point    o.totalseconds = 0.00;//From the time origin to the present second    o.TotalMilliseconds = 0.00;//From the time origin to the present millisecond    //Initialize Object    o.Init = function(timestamp){        varOdate= New Date(timestamp);        o. Year = odate.getFullYear();        o.Month = odate.GetMonth()+ 1;        o. Day = odate.getDate();        o.hours = odate.getHours();        o.minutes = odate.getminutes();        o.seconds = odate.getseconds();        o.milliseconds = odate.getmilliseconds();        o.TotalMilliseconds =Timestamp;        o.totalseconds =(Timestamp/ +).toFixed(2);        o.totalminutes =(Timestamp/ +/ -).toFixed(2);        o.totalHours =(Timestamp/ +/ -/ -).toFixed(2);        o.Totalday =(Timestamp/ +/ -/ -/ -).toFixed(2);        o.Totalmonth = o. Year *  A;        o.Totalyear = o. Year;    }    //No parameter returns empty object    if(arguments.length == 0){    }    Else if(typeof(arguments[0])=== "string"){        o.Init(New Date(arguments[0]));    }    Else if(typeof(arguments[0])=== "Number"){        o.Init(arguments[0]);    } Else if(typeof(arguments[0])=== "Object"){        o.Init(arguments[0]);    }    returnO;}

tinydate.js[v0.2] Optimized call mode

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.