亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js實(shí)現(xiàn)的日期操作類DateTime函數(shù)代碼

 更新時(shí)間:2010年03月16日 23:31:31   作者:  
感覺js自帶的Date類型對象用起來不是很方便,照著C#的DateTime做了一個(gè)

方法注解:

將指定的天數(shù)加到此實(shí)例的值上。

將指定的小時(shí)數(shù)加到此實(shí)例的值上。

將指定的分鐘數(shù)加到此實(shí)例的值上。

將指定的毫秒數(shù)加到此實(shí)例的值上。

將指定的月份數(shù)加到此實(shí)例的值上。

將指定的秒數(shù)加到此實(shí)例的值上。

將指定的年份數(shù)加到此實(shí)例的值上。

將此實(shí)例的值與指定的 Date 值相比較,并指示此實(shí)例是早于、等于還是晚于指定的 Date 值。

返回一個(gè)數(shù)值相同的新DateTime對象

返回一個(gè)值,該值指示此實(shí)例是否與指定的 DateTime 實(shí)例相等。

獲取此實(shí)例的日期部分。

獲取此實(shí)例所表示的日期為該月中的第幾天。

獲取此實(shí)例所表示的日期是星期幾。

獲取此實(shí)例所表示日期的小時(shí)部分。

獲取此實(shí)例所表示日期的分鐘部分。

獲取此實(shí)例所表示日期的毫秒部分。

獲取此實(shí)例所表示日期的月份部分。

獲取此實(shí)例的下個(gè)月一日的DateTime對象

獲取此實(shí)例的下一個(gè)周日的DateTime對象

獲取此實(shí)例的下一個(gè)周日的DateTime對象

獲取此實(shí)例所表示日期的秒部分。

返回此實(shí)例的Date值

獲取此實(shí)例所表示日期的年份部分。

指示此實(shí)例是否是DateTime對象

將當(dāng)前 DateTime 對象的值轉(zhuǎn)換為其等效的短日期字符串表示形式。

將當(dāng)前 DateTime 對象的值轉(zhuǎn)換為其等效的短時(shí)間字符串表示形式。

將當(dāng)前 DateTime 對象的值轉(zhuǎn)換為其等效的字符串表示形式。

驗(yàn)證Add系列的方法參數(shù)是否合法

繼承自Date的方法

比較 DateTime 的兩個(gè)實(shí)例,并返回它們相對值的指示。

返回指定年和月中的天數(shù)。

返回一個(gè)值,該值指示 DateTime 的兩個(gè)實(shí)例是否相等。

返回指定的年份是否為閏年的指示。

獲取一個(gè) DateTime 對象,該對象設(shè)置為此計(jì)算機(jī)上的當(dāng)前日期和時(shí)間,表示為本地時(shí)間。

將日期和時(shí)間的指定字符串表示形式轉(zhuǎn)換為其等效的 DateTime。

獲取當(dāng)前日期,其時(shí)間組成部分設(shè)置為 00:00:00。

復(fù)制代碼 代碼如下:

//表示時(shí)間上的一刻,通常以日期和當(dāng)天的時(shí)間表示。
function DateTime(year, month, day, hour, min, sec, millisec){
    var d = new Date();

    if (year || year == 0){
        d.setFullYear(year);
    }
    if (month || month == 0){
        d.setMonth(month - 1);
    }
    if (day || day == 0){
        d.setDate(day);
    }
    if (hour || hour == 0){
        d.setHours(hour);
    }
    if (min || min == 0){
        d.setMinutes(min);
    }
    if (sec || sec == 0){
        d.setSeconds(sec);
    }
    if (millisec || millisec == 0){
        d.setMilliseconds(millisec);
    }
    //將指定的天數(shù)加到此實(shí)例的值上。
    this.AddDays = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setDate(result.GetDay() + value);
        return result;
    }
    //將指定的小時(shí)數(shù)加到此實(shí)例的值上。
    this.AddHours = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setHours(result.GetHour() + value);
        return result;
    }
    //將指定的分鐘數(shù)加到此實(shí)例的值上。
    this.AddMinutes = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setMinutes(result.GetMinute() + value);
        return result;
    }
    //將指定的毫秒數(shù)加到此實(shí)例的值上。
    this.AddMilliseconds = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setMilliseconds(result.GetMillisecond() + value);
        return result;
    }
    //將指定的月份數(shù)加到此實(shí)例的值上。
    this.AddMonths = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setMonth(result.GetValue().getMonth() + value);
        return result;
    }
    //將指定的秒數(shù)加到此實(shí)例的值上。
    this.AddSeconds = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setSeconds(result.GetSecond() + value);
        return result;
    }
    //將指定的年份數(shù)加到此實(shí)例的值上。
    this.AddYears = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setFullYear(result.GetYear() + value);
        return result;
    }    
    //將此實(shí)例的值與指定的 Date 值相比較,并指示此實(shí)例是早于、等于還是晚于指定的 Date 值。
    this.CompareTo = function(other){
        var internalTicks = other.getTime();
        var num2 = d.getTime();
     if (num2 > internalTicks)
     {
     return 1;
     }
     if (num2 < internalTicks)
     {
     return -1;
     }
     return 0;
    }
    //返回一個(gè)數(shù)值相同的新DateTime對象
    this.Clone = function(){
        return new DateTime(
             this.GetYear()
            ,this.GetMonth()
            ,this.GetDay()
            ,this.GetHour()
            ,this.GetMinute()
            ,this.GetSecond()
            ,this.GetMillisecond());
    }
    //返回一個(gè)值,該值指示此實(shí)例是否與指定的 DateTime 實(shí)例相等。
    this.Equals = function(other){
        return this.CompareTo(other) == 0;
    }
    //獲取此實(shí)例的日期部分。
    this.GetDate = function(){
        var result = new DateTime(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0);
        return result ;
    }
    //獲取此實(shí)例所表示的日期為該月中的第幾天。
    this.GetDay = function(){
        return d.getDate();
    }
    //獲取此實(shí)例所表示的日期是星期幾。
    this.GetDayOfWeek = function(){
        return d.getDay();
    }
    //獲取此實(shí)例所表示日期的小時(shí)部分。
    this.GetHour = function(){
        return d.getHours();
    }
    //獲取此實(shí)例所表示日期的分鐘部分。
    this.GetMinute = function(){
        return d.getMinutes();
    }
    //獲取此實(shí)例所表示日期的毫秒部分。
    this.GetMillisecond = function(){
        return d.getMilliseconds();
    }
    //獲取此實(shí)例所表示日期的月份部分。
    this.GetMonth = function(){
        return d.getMonth() + 1;
    }
    //獲取此實(shí)例的下個(gè)月一日的DateTime對象
    this.GetNextMonthFirstDay = function(){
        var result = new DateTime(this.GetYear(), this.GetMonth(), 1, 0, 0, 0, 0);
        result = result.AddMonths(1);
        return result;
    }
    //獲取此實(shí)例的下一個(gè)周日的DateTime對象
    this.GetNextWeekFirstDay = function(){
        var result = this.GetDate();
        return result.AddDays(7 - result.GetDayOfWeek());
    }
    //獲取此實(shí)例的下一個(gè)周日的DateTime對象
    this.GetNextYearFirstDay = function(){
        return new DateTime(this.GetYear() + 1, 1, 1, 0, 0, 0, 0);
    }
    //獲取此實(shí)例所表示日期的秒部分。
    this.GetSecond = function(){
        return d.getSeconds();
    }
    //返回此實(shí)例的Date值
    this.GetValue = function(){
        return d;
    }
    //獲取此實(shí)例所表示日期的年份部分。
    this.GetYear = function(){
        return d.getFullYear();
    }
    //指示此實(shí)例是否是DateTime對象
    this.IsDateTime = function(){}
    //將當(dāng)前 DateTime 對象的值轉(zhuǎn)換為其等效的短日期字符串表示形式。
    this.ToShortDateString = function(){
        var result = "";
        result = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate();
        return result;    
    }
    //將當(dāng)前 DateTime 對象的值轉(zhuǎn)換為其等效的短時(shí)間字符串表示形式。
    this.ToShortTimeString = function(){
        var result = "";
        result = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
        return result;    
    }
    //將當(dāng)前 DateTime 對象的值轉(zhuǎn)換為其等效的字符串表示形式。
    this.ToString = function(format){
        if(typeof(format) == "string"){

        }
        return this.ToShortDateString() + " " + this.ToShortTimeString();
    }
    //驗(yàn)證Add系列的方法參數(shù)是否合法
    function ValidateAddMethodParam(param){
        if(typeof(param) != "number"){
            return false;
        }
        return true;
    }
    //繼承自Date的方法
    this.getTime = function(){
        return d.getTime();
    }
}

//比較 DateTime 的兩個(gè)實(shí)例,并返回它們相對值的指示。
DateTime.Compare = function(d1, d2){
    return d1.CompareTo(d2);
}
//返回指定年和月中的天數(shù)。
DateTime.DaysInMonth = function(year, month){
if ((month < 1) || (month > 12))
{
return "月份[" + month + "]超出范圍";
}
var numArray = DateTime.IsLeapYear(year) ? DateTime.DaysToMonth366 : DateTime.DaysToMonth365;
return (numArray[month] - numArray[month - 1]);
}
//返回一個(gè)值,該值指示 DateTime 的兩個(gè)實(shí)例是否相等。
DateTime.Equals = function(d1, d2){
    return d1.CompareTo(d2) == 0;
}
//返回指定的年份是否為閏年的指示。
DateTime.IsLeapYear = function(year)
{
if ((year < 1) || (year > 0x270f))
{
return "年份[" + year + "]超出范圍";
}
if ((year % 4) != 0)
{
return false;
}
if ((year % 100) == 0)
{
return ((year % 400) == 0);
}
return true;
}
//獲取一個(gè) DateTime 對象,該對象設(shè)置為此計(jì)算機(jī)上的當(dāng)前日期和時(shí)間,表示為本地時(shí)間。
DateTime.Now = new DateTime();
//將日期和時(shí)間的指定字符串表示形式轉(zhuǎn)換為其等效的 DateTime。
DateTime.Parse = function(s){
    var result = new DateTime();
    var value = result.GetValue();
    value.setHours(0,0,0,0);
    var dateRex = /\b[1-2][0-9][0-9][0-9][-]\d{1,2}[-]\d{1,2}\b/i;
    if(dateRex.test(s)){
        var dateStr = s.match(dateRex)[0];
        try{
            var dateParts = dateStr.split("-");
            var year = dateParts[0] - 0;
            var month = dateParts[1] - 1;
            var day = dateParts[2] - 0;
            value.setFullYear(year,month,day);
        }catch(ex){
            return null;
        }
        var timeRex = /\b\d{1,2}[:]\d{1,2}[:]\d{1,2}\b/i;
        if(timeRex.test(s)){
            var timeStr = s.match(timeRex)[0];
            try{
                var timeParts = timeStr.split(":");
                var hour = timeParts[0] - 0;
                var min = timeParts[1] - 0;
                var sec = timeParts[2] - 0;
                value.setHours(hour,min,sec);
            }catch(ex){

            }
        }
    }else{
        return null;
    }
    return result;
}
//獲取當(dāng)前日期,其時(shí)間組成部分設(shè)置為 00:00:00。
DateTime.Today = new DateTime(null, null, null, 0, 0, 0, 0);

//靜態(tài)字段
DateTime.DaysToMonth365 = [ 0, 0x1f, 0x3b, 90, 120, 0x97, 0xb5, 0xd4, 0xf3, 0x111, 0x130, 0x14e, 0x16d ];
DateTime.DaysToMonth366 = [ 0, 0x1f, 60, 0x5b, 0x79, 0x98, 0xb6, 0xd5, 0xf4, 0x112, 0x131, 0x14f, 0x16e ];

相關(guān)文章

最新評論