格式:
Format_Date_Set(Byval t,Byval ftype)
参数:
t:需要转换的日期时间
ftype:转换的格式规范
'转换时间,可以随意处理时间格式,非常方便
'比如2020-02-09 08:05:07
'yyyy,yy,y(yyyy)年份,对应2020,20,2020
'mm,m月份,对应02,2
'dd,d日,对应09,9
'hh,h小时,对应08,8
'ii,i分钟,对应05,5
'ss,s秒,对应07,7
'wwww,www,ww,w为周几,分别对应:Sunday,Sun,日,1
代码:
Function Format_Date_Set(Byval t,Byval ftype)
If isNull(t) Then t = now()
If Not IsDate(t) Then Exit Function
dim yyyy,yy,y,mm,m,dd,d,hh,h,ii,i,ss,s,wwww,www,ww,w
dim arr,j,weekArr,wArr,wcnArr
weekArr = Array( "Sunday" , "Monday" , "Tuesday" , "Wednesday" , "Thursday" ,"Friday" , "Saturday" )
wArr=Array( "Sun" , "Mon" , "Tue" , "Wed" , "Thur" , "Fri" , "Sat" )
wcnArr=Array( "日" , "一" , "二", "三", "四", "五", "六" )
yyyy=cstr(year(t)) : yy = right( yyyy,2 ) : y = yyyy
m=cstr(month(t)) : mm = m
If len(mm)=1 Then mm="0" & mm
d=cstr(day(t)) : dd = d
If len(dd)=1 Then dd="0" & dd
h = cstr(hour(t)) : hh = h
If len(hh)=1 Then hh="0" & hh
i = cstr(minute(t)) : ii = i
If len(ii)=1 Then ii="0" & ii
s = cstr(second(t)) : ss = s
If len(ss)=1 Then ss="0" & ss
w = weekday( t , 0 ) -1
wwww = weekArr( w )
www = wArr( w )
ww = wcnArr( w )
w = w + 1
ftype = LCase(ftype)
arr = array("yyyy" , "yy" , "y" , "mm" , "m" , "dd" , "d" , "hh" , "h" , "ii" , "i" , "ss" , "s" , "wwww","www","ww","w" )
t = CStr(ftype)
for j = 0 to ubound(arr)
If InStr( t, arr(j) ) > 0 Then
Execute( "t = replace( t, """ & arr(j) & """ , " & arr(j) & " )" )
end If
next
Format_Date_Set = t
End Function
应用:
response.Write Format_Date_Set(now(),"yyyy-mm-dd hh:ii:ss")
response.Write "<br>"
response.Write Format_Date_Set(now(),"yyyy-mm-dd 星期ww")
返回:
2020-08-21 16:48:35
2020-08-21 星期五