# 经过ASP代码实现时间格式化

www.myexceptions.net  网友分享于：2013-02-20  浏览：32次

Function Format_DateTime(S_DateTime,I_Format)
Dim y, m, d, h, mi, s
Format_DateTime = ""
If IsDate(S_DateTime) = False Then Exit Function
y = cstr(year(S_DateTime))
m = cstr(month(S_DateTime))
If len(m) = 1 Then m = "0" & m
d = cstr(day(S_DateTime))
If len(d) = 1 Then d = "0" & d
h = cstr(hour(S_DateTime))
If len(h) = 1 Then h = "0" & h
mi = cstr(minute(S_DateTime))
If len(mi) = 1 Then mi = "0" & mi
s = cstr(second(S_DateTime))
If len(s) = 1 Then s = "0" & s
Select Case I_Format
Case 0
Format_DateTime = m & "-" & d
Case 1
' yyyy-mm-dd hh:mm:ss
Format_DateTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
Case 2
' yyyy-mm-dd
Format_DateTime = y & "-" & m & "-" & d
Case 3
' hh:mm:ss
Format_DateTime = h & ":" & mi & ":" & s
Case 4
' yyyy年mm月dd日
Format_DateTime = y & "年" & m & "月" & d & "日"
Case 5
' yyyymmdd
Format_DateTime = y & m & d
Case 6
' yyyy-mm-dd hh:mm
Format_DateTime = y & "-" & m & "-" & d & " " & h & ":" & mi
End Select
End Function

Format_DateTime(Now(),0)

http://www.xszlo.com/article/2012-11-29/7536.html