【编者按】:网学网ASP为您提供asp 将日期格式化为需要的格式参考,解决您在asp 将日期格式化为需要的格式学习中工作中的难题,参考学习。
<%
''******************************
''函数:FormatDate(DateAndTime, para)
''参数:DateAndTime,要格式化的日期时间;para,样式。
''作者:阿里西西
''日期:2007/7/12
''描述:将日期格式化为需要的格式
''示例:<%=FormatDate(now(), 3)%>
''******************************
Public Function FormatDate(DateAndTime, para)
On Error Resume Next
Dim y, m, d, h, mi, s, strDateTime
FormatDate = DateAndTime
If Not IsNumeric(para) Then Exit Function
If Not IsDate(DateAndTime) Then Exit Function
y = CStr(Year(DateAndTime))
m = CStr(Month(DateAndTime))
If Len(m) = 1 Then m = "0" & m
d = CStr(Day(DateAndTime))
If Len(d) = 1 Then d = "0" & d
h = CStr(Hour(DateAndTime))
If Len(h) = 1 Then h = "0" & h
mi = CStr(Minute(DateAndTime))
If Len(mi) = 1 Then mi = "0" & mi
s = CStr(Second(DateAndTime))
If Len(s) = 1 Then s = "0" & s
Select Case para
Case "1"
strDateTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
Case "2"
strDateTime = y & "-" & m & "-" & d
Case "3"
strDateTime = y & "/" & m & "/" & d
Case "4"
strDateTime = y & "年" & m & "月" & d & "日"
Case "5"
strDateTime = m & "-" & d & " " & h & ":" & mi
Case "6"
strDateTime = m & "/" & d
Case "7"
strDateTime = m & "月" & d & "日"
Case "8"
strDateTime = y & "年" & m & "月"
Case "9"
strDateTime = y & "-" & m
Case "10"
strDateTime = y & "/" & m
Case "11"
strDateTime = right(y,2) & "-" &m & "-" & d & " " & h & ":" & mi
Case "12"
strDateTime = right(y,2) & "-" &m & "-" & d
Case "13"
strDateTime = m & "-" & d
Case Else
strDateTime = DateAndTime
End Select
FormatDate = strDateTime
End Function
%>