欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

方法注解:

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

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

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

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

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

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

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

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

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

返回一個值,該值指示此實例是否與指定的 DateTime 實例相等。

獲取此實例的日期部分。

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

獲取此實例所表示的日期是星期幾。

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

獲取此實例所表示日期的分鐘部分。

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

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

獲取此實例的下個月一日的DateTime對象

獲取此實例的下一個周日的DateTime對象

獲取此實例的下一個周日的DateTime對象

獲取此實例所表示日期的秒部分。

返回此實例的Date值

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

指示此實例是否是DateTime對象

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

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

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

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

繼承自Date的方法

比較 DateTime 的兩個實例,并返回它們相對值的指示。

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

返回一個值,該值指示 DateTime 的兩個實例是否相等。

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

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

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

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

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

//表示時間上的一刻,通常以日期和當(dāng)天的時間表示。
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ù)加到此實例的值上。
    this.AddDays = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setDate(result.GetDay() + value);
        return result;
    }
    //將指定的小時數(shù)加到此實例的值上。
    this.AddHours = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setHours(result.GetHour() + value);
        return result;
    }
    //將指定的分鐘數(shù)加到此實例的值上。
    this.AddMinutes = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setMinutes(result.GetMinute() + value);
        return result;
    }
    //將指定的毫秒數(shù)加到此實例的值上。
    this.AddMilliseconds = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setMilliseconds(result.GetMillisecond() + value);
        return result;
    }
    //將指定的月份數(shù)加到此實例的值上。
    this.AddMonths = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setMonth(result.GetValue().getMonth() + value);
        return result;
    }
    //將指定的秒數(shù)加到此實例的值上。
    this.AddSeconds = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setSeconds(result.GetSecond() + value);
        return result;
    }
    //將指定的年份數(shù)加到此實例的值上。
    this.AddYears = function(value){
        if(!ValidateAddMethodParam(value)){
            return null;
        }
        var result = this.Clone();
        result.GetValue().setFullYear(result.GetYear() + value);
        return result;
    }    
    //將此實例的值與指定的 Date 值相比較,并指示此實例是早于、等于還是晚于指定的 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;
    }
    //返回一個數(shù)值相同的新DateTime對象
    this.Clone = function(){
        return new DateTime(
             this.GetYear()
            ,this.GetMonth()
            ,this.GetDay()
            ,this.GetHour()
            ,this.GetMinute()
            ,this.GetSecond()
            ,this.GetMillisecond());
    }
    //返回一個值,該值指示此實例是否與指定的 DateTime 實例相等。
    this.Equals = function(other){
        return this.CompareTo(other) == 0;
    }
    //獲取此實例的日期部分。
    this.GetDate = function(){
        var result = new DateTime(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0);
        return result ;
    }
    //獲取此實例所表示的日期為該月中的第幾天。
    this.GetDay = function(){
        return d.getDate();
    }
    //獲取此實例所表示的日期是星期幾。
    this.GetDayOfWeek = function(){
        return d.getDay();
    }
    //獲取此實例所表示日期的小時部分。
    this.GetHour = function(){
        return d.getHours();
    }
    //獲取此實例所表示日期的分鐘部分。
    this.GetMinute = function(){
        return d.getMinutes();
    }
    //獲取此實例所表示日期的毫秒部分。
    this.GetMillisecond = function(){
        return d.getMilliseconds();
    }
    //獲取此實例所表示日期的月份部分。
    this.GetMonth = function(){
        return d.getMonth() + 1;
    }
    //獲取此實例的下個月一日的DateTime對象
    this.GetNextMonthFirstDay = function(){
        var result = new DateTime(this.GetYear(), this.GetMonth(), 1, 0, 0, 0, 0);
        result = result.AddMonths(1);
        return result;
    }
    //獲取此實例的下一個周日的DateTime對象
    this.GetNextWeekFirstDay = function(){
        var result = this.GetDate();
        return result.AddDays(7 - result.GetDayOfWeek());
    }
    //獲取此實例的下一個周日的DateTime對象
    this.GetNextYearFirstDay = function(){
        return new DateTime(this.GetYear() + 1, 1, 1, 0, 0, 0, 0);
    }
    //獲取此實例所表示日期的秒部分。
    this.GetSecond = function(){
        return d.getSeconds();
    }
    //返回此實例的Date值
    this.GetValue = function(){
        return d;
    }
    //獲取此實例所表示日期的年份部分。
    this.GetYear = function(){
        return d.getFullYear();
    }
    //指示此實例是否是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)換為其等效的短時間字符串表示形式。
    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();
    }
    //驗證Add系列的方法參數(shù)是否合法
    function ValidateAddMethodParam(param){
        if(typeof(param) != "number"){
            return false;
        }
        return true;
    }
    //繼承自Date的方法
    this.getTime = function(){
        return d.getTime();
    }
}

//比較 DateTime 的兩個實例,并返回它們相對值的指示。
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]);
}
//返回一個值,該值指示 DateTime 的兩個實例是否相等。
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;
}
//獲取一個 DateTime 對象,該對象設(shè)置為此計算機上的當(dāng)前日期和時間,表示為本地時間。
DateTime.Now = new DateTime();
//將日期和時間的指定字符串表示形式轉(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è)置為 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)文章

  • 微信小程序跨頁面數(shù)據(jù)傳遞事件響應(yīng)實現(xiàn)過程解析

    微信小程序跨頁面數(shù)據(jù)傳遞事件響應(yīng)實現(xiàn)過程解析

    這篇文章主要介紹了微信小程序跨頁面數(shù)據(jù)傳遞事件響應(yīng)實現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-12-12
  • JavaScript實現(xiàn)驗證碼案例

    JavaScript實現(xiàn)驗證碼案例

    這篇文章主要為大家詳細(xì)介紹了JavaScript實現(xiàn)驗證碼案例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • css和js實現(xiàn)彈出登錄居中界面完整代碼

    css和js實現(xiàn)彈出登錄居中界面完整代碼

    這篇文章主要介紹了css和js實現(xiàn)彈出登錄居中界面,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-11-11
  • JavaScript使用atan2來繪制箭頭和曲線的實例

    JavaScript使用atan2來繪制箭頭和曲線的實例

    下面小編就為大家?guī)硪黄狫avaScript使用atan2來繪制箭頭和曲線的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • 前端的框架TDesign小程序組件庫體驗

    前端的框架TDesign小程序組件庫體驗

    TDesign是騰訊各業(yè)務(wù)團(tuán)隊在服務(wù)業(yè)務(wù)過程中沉淀的一套企業(yè)級設(shè)計體系,下面這篇文章主要給大家介紹了關(guān)于前端的框架TDesign小程序組件庫體驗的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2022-11-11
  • js實現(xiàn)的xml對象轉(zhuǎn)json功能示例

    js實現(xiàn)的xml對象轉(zhuǎn)json功能示例

    這篇文章主要介紹了js實現(xiàn)的xml對象轉(zhuǎn)json功能,結(jié)合實例形式分析了javascript轉(zhuǎn)換成xml所涉及的字符串、對象、數(shù)組、遍歷等操作技巧與使用方法,需要的朋友可以參考下
    2016-12-12
  • JS獲取及驗證開始結(jié)束日期的方法

    JS獲取及驗證開始結(jié)束日期的方法

    這篇文章主要介紹了JS獲取及驗證開始結(jié)束日期的方法.涉及javascript針對日期的獲取、比較及判斷等技巧,需要的朋友可以參考下
    2016-08-08
  • js動態(tài)設(shè)置select下拉菜單的默認(rèn)選中項實例

    js動態(tài)設(shè)置select下拉菜單的默認(rèn)選中項實例

    今天小編就為大家分享一篇js動態(tài)設(shè)置select下拉菜單的默認(rèn)選中項實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • JavaScript獲得url查詢參數(shù)的方法

    JavaScript獲得url查詢參數(shù)的方法

    這篇文章主要介紹了JavaScript獲得url查詢參數(shù)的方法,可實現(xiàn)針對URL中參數(shù)分析的功能,需要的朋友可以參考下
    2015-07-07
  • H5如何實現(xiàn)喚起APP及調(diào)試bug解決

    H5如何實現(xiàn)喚起APP及調(diào)試bug解決

    這篇文章主要為大家介紹了H5如何實現(xiàn)喚起APP及調(diào)試bug解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-05-05

最新評論