格式:
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 星期五