LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

[点晴永久免费OA]日期函数扩展类Ver0.1.1

admin
2022年7月4日 21:36 本文热度 591
代码如下:
<%
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
%>
</body>
</html>

该文章在 2022/7/4 21:36:24 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved