当前位置: 移动技术网 > IT编程>开发语言>Asp > 日期函数扩展类Ver0.1.1

日期函数扩展类Ver0.1.1

2017年12月12日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

<%
'转发时请保留此声明信息,这段声明不并会影响你的速度!
'**************************   【日期扩展类】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>


下载文件

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网