ASP时间格式化函数
日期:2017-06-15
- '================================================
- '函数名:FormatDate
- '作 用:格式化日期
- '参 数:DateAndTime (原日期和时间)
- ' Format (新日期格式)
- '返回值:格式化后的日期
- '================================================
- Function FormatDate(DateAndTime, Format)
- On Error Resume Next
- Dim yy,y, m, d, h, mi, s, strDateTime
- FormatDate = DateAndTime
- If Not IsNumeric(Format) Then Exit Function
- If Not IsDate(DateAndTime) Then Exit Function
- yy = CStr(Year(DateAndTime))
- y = Mid(CStr(Year(DateAndTime)),3)
- 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 Format
- Case "1"
- strDateTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
- Case "2"
- strDateTime = yy & m & d & h & mi & s
- '返回12位 直到秒 的时间字符串
- Case "3"
- strDateTime = yy & m & d & h & mi
- '返回12位 直到分 的时间字符串
- Case "4"
- strDateTime = yy & "年" & m & "月" & d & "日"
- Case "5"
- strDateTime = m & "-" & d
- 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 = y & "-" & m & "-" & d
- Case "12"
- strDateTime = y & "/" & m & "/" & d
- Case "13"
- strDateTime = yy & "." & m & "." & d
- Case "14"
- strDateTime = yy & "/" & m & "/" & d
- Case "15"
- strDateTime = yy & "-" & m & "-" & d
- Case Else
- strDateTime = DateAndTime
- End Select
- FormatDate = strDateTime
- End Function