日期函數擴充類Ver0.1.1_ASP CLASS類

來源:互聯網
上載者:User
複製代碼 代碼如下:

<%
'轉寄時請保留此聲明資訊,這段聲明不並會影響你的速度!
'**************************   【日期擴充類】Ver 0.1.1********************************
'開發人:        Sman、Net Fetch
'開發日期:        2005-11-11
'版本號碼:        Ver 0.1.1

'官方網站:http://www.sman.cn     http://www.ad0.cn
'電子郵件:huihui3030@126.com    NetFetchStudio@163.com  
'每日線上QQ:19341293             32050450
'著作權聲明:著作權沒有,盜版不究,源碼公開,歡迎盜版,歡迎你到官方網站來尋求支援。
'如有任何改進之處,麻煩轉寄或者反饋一份到 huihui3030@126.com、NetFetchStudio@163.com,Thanks!
'詳細使用說明或範例請見下載附件或到官方網站或Email聯絡下載!
'************************************************************************************

Class DateFunEx

    Private d_
    Private firstweekofyear_
    Private firstdayofweek_

    Private Sub class_initialize()
        d_                     = date() '預設當前日期
        firstdayofweek_     = 2    'vbMonday
        firstweekofyear_     = 1    '由 1 月 1 日所在的星期開始。
    End Sub

    '屬性 setDate 日期
    Public Property Let setDate(value) 
        On Error Resume Next
        If IsNumeric(value) Then
            value = Cint(value)
            If len(value)< 3 Then value = "20" & right("0"&value,2)
            value = value & "-1" 
        End If 
        d_ = cDate(value)
    End Property

    '屬性 firstweekofyear 每年的第一周(詳細設定請參照VBS手冊)
    Public Property Let firstweekofyear(value)
        firstweekofyear_ = cInt(value)
    End Property

    '屬性 FirstDayofWeek 每周的第一天(詳細設定請參照VBS手冊)
    Public Property Let firstdayofweek(value)
        firstdayofweek_ = cInt(value)
    End Property


    '------------------------------
    ' 功能說明:算第幾周的星期幾是幾號
    ' 參數說明:y 年,w周,week 星期 (星期一1 星期天7)
    '------------------------------
    Public Function GetWeekDate(y, w, DayofWeek)
        Dim NewYearDay
        NewYearDay = CDate(y & "-1-1") '元旦
        GetWeekDate = ((NewYearDay - Weekday(NewYearDay, firstdayofweek_)) + (w - 1) * 7 + DayofWeek)
    End Function

    '------------------------------
    ' 功能說明:獲得某年某月的天數
    '------------------------------
    Public Function GetMonthDayCount()
        GetMonthDayCount = DateDiff("d", d_, DateAdd("m", 1, d_))
    End Function

    '------------------------------
    ' 功能說明:得到某年某月的第一天
    '------------------------------
    Public Function GetMonthFirstDay()
        GetMonthFirstDay = CDate( Year(d_) & "-" & Month(d_) & "-1")
    End Function

    '------------------------------
    ' 功能說明:得到某年的某月的最後一天
    '------------------------------
    Public Function GetMonthLastDay()
        GetMonthLastDay = CDate( Year(d_) & "-"&Month(d_) & "-" & DateDiff("d", d_, DateAdd("m", 1, d_)))
    End Function

    '------------------------------
    ' 功能說明:某日所在的周的第一天的日期
    '------------------------------
    Public Function WeekFirstDay()
        WeekFirstDay = GetWeekDate(Year(d_), DatePart("ww", d_,firstdayofweek_,firstweekofyear_), 1)
    End Function

    '------------------------------
    ' 功能說明:某日所在的周的第最後一天的日期
    '------------------------------
    Public Function WeekLastDay()
        WeekLastDay = GetWeekDate(Year(d_), DatePart("ww", d_,firstdayofweek_,firstweekofyear_), 7)
    End Function

End Class
%>

測試頁面:
複製代碼 代碼如下:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<% Option Explicit %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Test_clsDateFunEx</title>
</head>

<body>
<!--#include file="clsDateFunEx.asp" -->
<%
Dim myDateFun,strDate 
strDate = "2005-4-1"
Set myDateFun = new DateFunEx 
    myDateFun.setDate = strDate
    Response.write "2006年第2周的星期一是幾號:" & _
                         myDateFun.GetWeekDate(2006,2,1) &"<br>"
    Response.Write "2005年4月的天數:"&_
                         myDateFun.GetMonthDayCount & "<br>"
    Response.Write "2005年4月的第一天:"&_
                         myDateFun.GetMonthFirstDay & "<br>"
    Response.Write "2005年4月的最後一天:"&_
                         myDateFun.GetMonthLastDay & "<br>"
    Response.Write "2005年4月1日所在的周的第一天的日期:"&_
                         myDateFun.WeekFirstDay & "<br>"
    Response.Write "2005年4月1日所在的周的第最後一天的日期:" & _
                        myDateFun.WeekLastDay & "<br>"
Set myDateFun = Nothing
%>
<br><br><br>
</body>
</html>


下載此檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.