asp 将日期格式化为需要的格式

2018-09-06 11:32

阅读:825

  <%
******************************
函数:FormatDate(DateAndTime,para)
参数:DateAndTime,要格式化的日期时间;para,样式。
作者:阿里西西
日期:2007/7/12
描述:将日期格式化为需要的格式
示例:<%=FormatDate(now(),3)%>
******************************
PublicFunctionFormatDate(DateAndTime,para)
OnErrorResumeNext
Dimy,m,d,h,mi,s,strDateTime
FormatDate=DateAndTime
IfNotIsNumeric(para)ThenExitFunction
IfNotIsDate(DateAndTime)ThenExitFunction
y=CStr(Year(DateAndTime))
m=CStr(Month(DateAndTime))
IfLen(m)=1Thenm=0&m
d=CStr(Day(DateAndTime))
IfLen(d)=1Thend=0&d
h=CStr(Hour(DateAndTime))
IfLen(h)=1Thenh=0&h
mi=CStr(Minute(DateAndTime))
IfLen(mi)=1Thenmi=0&mi
s=CStr(Second(DateAndTime))
IfLen(s)=1Thens=0&s
SelectCasepara
Case1
strDateTime=y&-&m&-&d&&h&:&mi&:&s
Case2
strDateTime=y&-&m&-&d
Case3
strDateTime=y&/&m&/&d
Case4
strDateTime=y&年&m&月&d&日
Case5
strDateTime=m&-&d&&h&:&mi
Case6
strDateTime=m&/&d
Case7
strDateTime=m&月&d&日
Case8
strDateTime=y&年&m&月
Case9
strDateTime=y&-&m
Case10
strDateTime=y&/&m
Case11
strDateTime=right(y,2)&-&m&-&d&&h&:&mi
Case12
strDateTime=right(y,2)&-&m&-&d
Case13
strDateTime=m&-&d
CaseElse
strDateTime=DateAndTime
EndSelect
FormatDate=strDateTime
EndFunction
%>


评论


亲,登录后才可以留言!