Asp基本日期函数:
函数 语法 说明 示例
Now Now() 取得系统当前的日期和时间
Date Date() 取得系统当前的日期
Time Time() 取得系统当前的时间
Year Year(Date) 取得给定日期的年份
Month Month(Date) 取得给定日期的月份
Day Day(Date) 取得给定日期是几号
Hour Hour(time) 取得给定时间是第几小时
Minute Minute(time) 取得给定时间是第几分钟
Second Second(time) 取得给守时间是第几秒
WeekDay WeekDay(Date) 取得给定日期是星期几的整数,1表示星期日,2表示星期一,依此类推
DateDiff("Var",Var1,Var2)
Var:日期或时间间隔因子,有如下参数:yyyy 年 m月 d 日 ww星期 h小时 s秒
Var1:第一个日期或时间
Var2:第二个日期或时间,比Var1晚 计算两个日期或时间的间隔
DateAdd("Var",Var1,Var2)
Var:日期或时间间隔因子:
Var1:日期或时间间隔倍数
Var2:日期或时间的基准 对两个日期或时间作加法
如果计算的日期是在公元 100 年之前,则会产生错误。
FormatDateTime FormatDateTime(Date,vbShortDate) 转化为短日期格式 FromatDateTime(Date(),vbLongDate) "以长日期格式显示
FormatDateTime(Date,vbLongDate) 转化为长日期格式
FormatDateTime(Date,vbShortTime) 转化为短时间格式
FormatDateTime(Date,vbLongTime) 转化为长时间格式
ASP日期和时间函数参考
日期函数扩展类代码 (clsDateFunEx_Power by Sman & Net Fetch):
调用代码
'日期转换函数
'*************************************
Function DateToStr(DateTime,ShowType)
Dim DateMonth,DateDay,DateHour,DateMinute,DateWeek,DateSecond
Dim FullWeekday,shortWeekday,Fullmonth,Shortmonth,TimeZone1,TimeZone2
TimeZone1=\"+0800\"
TimeZone2=\"+08:00\"
FullWeekday=Array(\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\")
shortWeekday=Array(\"Sun\",\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\")
Fullmonth=Array(\"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\"July\",\"August\",\"September\",\"October\",\"November\",\"December\")
Shortmonth=Array(\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\",\"Jul\",\"Aug\",\"Sep\",\"Oct\",\"Nov\",\"Dec\")
DateMonth=Month(DateTime)
DateDay=Day(DateTime)
DateHour=Hour(DateTime)
DateMinute=Minute(DateTime)
DateWeek=weekday(DateTime)
DateSecond=Second(DateTime)
If Len(DateMonth)<2 Then DateMonth=\"0\"&DateMonth
If Len(DateDay)<2 Then DateDay=\"0\"&DateDay
If Len(DateMinute)<2 Then DateMinute=\"0\"&DateMinute
Select Case ShowType
Case \"Y-m-d\"
DateToStr=Year(DateTime)&\"-\"&DateMonth&\"-\"&DateDay
Case \"Y-m-d H:I A\"
Dim DateAMPM
If DateHour>12 Then
DateHour=DateHour-12
DateAMPM=\"PM\"
Else
DateHour=DateHour
DateAMPM=\"AM\"
End If
If Len(DateHour)<2 Then DateHour=\"0\"&DateHour
DateToStr=Year(DateTime)&\"-\"&DateMonth&\"-\"&DateDay&\" \"&DateHour&\":\"&DateMinute&\" \"&DateAMPM
Case \"Y-m-d H:I:S\"
If Len(DateHour)<2 Then DateHour=\"0\"&DateHour
If Len(DateSecond)<2 Then DateSecond=\"0\"&DateSecond
DateToStr=Year(DateTime)&\"-\"&DateMonth&\"-\"&DateDay&\" \"&DateHour&\":\"&DateMinute&\":\"&DateSecond
Case \"YmdHIS\"
DateSecond=Second(DateTime)
If Len(DateHour)<2 Then DateHour=\"0\"&DateHour
If Len(DateSecond)<2 Then DateSecond=\"0\"&DateSecond
DateToStr=Year(DateTime)&DateMonth&DateDay&DateHour&DateMinute&DateSecond
Case \"ym\"
DateToStr=Right(Year(DateTime),2)&DateMonth
Case \"d\"
DateToStr=DateDay
Case \"ymd\"
DateToStr=Right(Year(DateTime),4)&DateMonth&DateDay
Case \"mdy\"
Dim DayEnd
select Case DateDay
Case 1
DayEnd=\"st\"
Case 2
DayEnd=\"nd\"
Case 3
DayEnd=\"rd\"
Case Else
DayEnd=\"th\"
End Select
DateToStr=Fullmonth(DateMonth-1)&\" \"&DateDay&DayEnd&\" \"&Right(Year(DateTime),4)
Case \"w,d m y H:I:S\"
DateSecond=Second(DateTime)
If Len(DateHour)<2 Then DateHour=\"0\"&DateHour
If Len(DateSecond)<2 Then DateSecond=\"0\"&DateSecond
DateToStr=shortWeekday(DateWeek-1)&\",\"&DateDay&\" \"& Left(Fullmonth(DateMonth-1),3) &\" \"&Right(Year(DateTime),4)&\" \"&DateHour&\":\"&DateMinute&\":\"&DateSecond&\" \"&TimeZone1
Case \"y-m-dTH:I:S\"
If Len(DateHour)<2 Then DateHour=\"0\"&DateHour
If Len(DateSecond)<2 Then DateSecond=\"0\"&DateSecond
DateToStr=Year(DateTime)&\"-\"&DateMonth&\"-\"&DateDay&\"T\"&DateHour&\":\"&DateMinute&\":\"&DateSecond&TimeZone2
Case Else
If Len(DateHour)<2 Then DateHour=\"0\"&DateHour
DateToStr=Year(DateTime)&\"-\"&DateMonth&\"-\"&DateDay&\" \"&DateHour&\":\"&DateMinute
End Select
End Function
【日期函数扩展类】Ver 0.1.1 经Sman改正部分错误
'转发时请保留此声明信息,这段声明不并会影响你的速度!
'************************** 【日期函数扩展类】Ver 0.1.1********************************
'开发人: Sman、Net Fetch
'开发日期: 2005-11-11
'版本号: Ver 0.1.1
'官方网站:http://www.ad0.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
%>
Asp日期转换扩展类
ASP日期和时间函数参考
ASP日期函数