asp格式化时间
代码:
' ============================================
' 格式化时间(显示)
' 参数:n_Flag
' 1:"yyyy-mm-dd hh:mm:ss"
' 2:"yyyy-mm-dd"
' 3:"hh:mm:ss"
' 4:"yyyy年mm月dd日"
' 5:"yyyymmdd"
' 6:"yyyymmddhhmmss"
' 7:"yyyy-mm-ddThh:mm:ss+00:00"
' ============================================
Function Format_Time(s_Time, n_Flag)
Dim y
Dim m
Dim d
Dim h
Dim mi
Dim s
Format_Time = ""
If IsDate(s_Time) = False Then Exit Function
y = CStr(Year(s_Time))
m = CStr(Month(s_Time))
If Len(m) = 1 Then m = "0" & m
d = CStr(Day(s_Time))
If Len(d) = 1 Then d = "0" & d
h = CStr(Hour(s_Time))
If Len(h) = 1 Then h = "0" & h
mi = CStr(Minute(s_Time))
If Len(mi) = 1 Then mi = "0" & mi
s = CStr(Second(s_Time))
If Len(s) = 1 Then s = "0" & s
Select Case n_Flag
Case 1
' yyyy-mm-dd hh:mm:ss
Format_Time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
Case 2
' yyyy-mm-dd
Format_Time = y & "-" & m & "-" & d
Case 3
' hh:mm:ss
Format_Time = h & ":" & mi & ":" & s
Case 4
' yyyy年mm月dd日
Format_Time = y & "年" & m & "月" & d & "日"
Case 5
' yyyymmdd
Format_Time = y & m & d
Case 6
'yyyymmddhhmmss
format_time = y & m & d & h & mi & s
Case 7
' 2021-03-04T04:54:03+00:00
Format_Time = y & "-" & m & "-" & d & "T" & h & ":" & mi & ":" & s & "+00:00"
End Select
End Function
使用方法:
<%=Format_Time(now(),2)%>
明月浩空》原创,转载请保留文章出处。
本文链接:https://blog.myhkw.cn/asp_format_time.html
版权声明:若无特殊注明,本文为《正文到此结束
发表吐槽
你肿么看?
已有1条吐槽