日期函数扩展类Ver0.1.1

a122996325a

a122996325a

2016-02-19 12:24

下面图老师小编跟大家分享一个简单易学的日期函数扩展类Ver0.1.1教程,get新技能是需要行动的,喜欢的朋友赶紧收藏起来学习下吧!

代码如下:

%
'转发时请保留此声明信息,这段声明不并会影响你的速度!
'**************************   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" /
titleTest_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
%
brbrbr
/body
/html

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/webkaifa/)
展开更多 50%)
分享

猜你喜欢

日期函数扩展类Ver0.1.1

Web开发
日期函数扩展类Ver0.1.1

校验日期的函数

电脑网络
校验日期的函数

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

Excel日期时间函数

电脑入门
Excel日期时间函数

Oracle日期函数简介

编程语言 网络编程
Oracle日期函数简介

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

Excel函数详解日期和时间函数

电脑入门
Excel函数详解日期和时间函数

CToolBar扩展类CToolBarEx

编程语言 网络编程
CToolBar扩展类CToolBarEx

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Win8系统中的宽带连接在哪里

Win8系统中的宽带连接在哪里

AjaxUI:滑动条

AjaxUI:滑动条
下拉加载更多内容 ↓