您所在的位置:小祥子 » 编程 » ASP » 正文

ASP格式化时间函数

时间:2015-02-10 编辑:本站 来源:本站原创

网上格式化时间的Function很多,今天为大家介绍一个比较全的函数。

使用方法 <%=DateFormat(now(),1)%>

Function  DateFormat(DateStr,Types)
    Dim DateString
 if IsDate(DateStr) = False then
  DateString = ""
 end if
 Select Case Types
   Case "1"
    DateString = Year(DateStr)&"-"&Month(DateStr)&"-"&Day(DateStr)
   Case "2"
    DateString = Year(DateStr)&"."&Month(DateStr)&"."&Day(DateStr)
   Case "3"
    DateString = Year(DateStr)&"/"&Month(DateStr)&"/"&Day(DateStr)
   Case "4"
    DateString = Month(DateStr)&"/"&Day(DateStr)&"/"&Year(DateStr)
   Case "5"
    DateString = Day(DateStr)&"/"&Month(DateStr)&"/"&Year(DateStr)
   Case "6"
    DateString = Month(DateStr)&"-"&Day(DateStr)&"-"&Year(DateStr)
   Case "7"
    DateString = Month(DateStr)&"."&Day(DateStr)&"."&Year(DateStr)
   Case "8"
    DateString = Month(DateStr)&"-"&Day(DateStr)
   Case "9"
    DateString = Month(DateStr)&"/"&Day(DateStr)
   Case "10"
    DateString = Month(DateStr)&"."&Day(DateStr)
   Case "11"
    DateString = Month(DateStr)&"月"&Day(DateStr)&"日"
   Case "12"
    DateString = Day(DateStr)&"日"&Hour(DateStr)&"时"
   case "13"
    DateString = Day(DateStr)&"日"&Hour(DateStr)&"点"
   Case "14"
    DateString = Hour(DateStr)&"时"&Minute(DateStr)&"分"
   Case "15"
    DateString = Hour(DateStr)&":"&Minute(DateStr)
   Case "16"
    DateString = Year(DateStr)&"年"&Month(DateStr)&"月"&Day(DateStr)&"日"
   Case Else
      DateString = DateStr
  End Select
  DateFormat = DateString
End Function

关键词:时间 格式化