No need to talk about the date function? Is the General date comparison, the date addition, get the current time
The Code is as follows:
/*
* Function name: DateUtil
* OPERATOR: yithcn
* Function Description: Date Functions
* Instructions:
* Creation date: 2010.10.14
*/
Var DateUtil = {};
DateUtil. base = 60*60*24*1000;
DateUtil. Add = function (num, sDate ){
Num = num | 0;
SDate = sDate | new Date ();
Var base = this. base * num;
Var todayMs = sDate. getTime ();
TodayMs + = base;
SDate. setTime (todayMs );
Var m = (sDate. getMonth () + 1 );
M = m <10? "0" + m: m;
Var d = sDate. getDate ();
D = d <10? "0" + d: d;
Var y = sDate. getFullYear ();
Return m + "/" + d + "/" + y;
};
DateUtil. Diff = function (sDate, eDate, mode ){
If (typeof sDate = "string ")
SDate = new Date (sDate );
If (typeof eDate = "string ")
EDate = new Date (eDate );
SDate = sDate | new Date ();
EDate = eDate | new Date ();
Try {
SDate. getYear ();
} Catch (e ){
Return (0 );
}
Var result = Math. abs (eDate-sDate );
Switch (mode ){
Case "y ":
Result/= this. base * 365;
Break;
Case "m ":
Result/= this. base * 365/12;
Break;
Case "w ":
Result/= this. base * 7;
Break;
Default:
Result/= this. base;
Break;
}
Return (Math. floor (result ));
};
DateUtil. Time = function (hasSec ){
Var date = new Date ();
Return date. getHours () + ":" + date. getMinutes () + (hasSec? ":" + Date. getSeconds ():"");
};
DateUtil. TimeSplit = function (hasSec ){
Var date = new Date ();
Return {Hour: date. getHours (), Minute: date. getMinutes (), Second: (hasSec? ":" + Date. getSeconds ():"")};
};