發表于:2011-06-15 00:00:00來源:不懂戀愛魚兒人氣:3112
<%@LANGUAGE="VBSCRIPT " CODEPAGE="936"%>
<% Option Explicit %>
<style type="text/css">
* {
margin:10px;
line-height:180%
}
.font {
FONT-SIZE:14px;
font-weight:bold;
COLOR:#FD0101;
FONT-FAMILY:Georgia;
}
</style>
<%
'函數調用示例:
Response.Write FormatTime(Now(),"{Y}-{M}-{D} {H}:{N}:{S}") & "<br>"
Response.Write FormatTime(Now(),"{Y}年{M}月{D}日 {H}時{N}分(fēn){S}秒") & "<br>"
Response.Write FormatTime(Now(),"{w},{D} {Me} {Y}") & "<br>"
Response.Write ("<font class=""font"">"&FormatTime(Now(),"{w},{Y}-{M}-{D}")&"</font>")
'==================================================================
'函數:FormatTime
'功能:日期時間格式化
'參數:DateTime,日期時間
'Template,格式化模闆
'返回:格式化後的字串
'備注:模闆标簽注釋
' {Y}:年
' {y}:2位年
' {M}:月
' {m}:補位月,例:01,02
' {ME}:英文月份
' {Me}:英文月份縮寫
' {D}:日
' {d}:補位日
' {H}:時
' {h}:補位時
' {N}:分(fēn)
' {n}:補位分(fēn)
' {S}:秒
' {s}:補位秒
' {W}:星期幾英文
' {w}:星期幾英文縮寫
'==================================================================
Function FormatTime(DateTime,Template)
If (Not IsDate(DateTime)) or Template = "" Then
FormatTime = Template
Exit Function
End If
Dim dtmY,dtmM,dtmD,dtmH ,dtmN,dtmS,dtmW
Dim arrFW,arrSW,arrFM,arrSM
dtmY = Year(DateTime)
dtmM = Month(DateTime)
dtmD = Day(DateTime)
dtmH = Hour(DateTime)
dtmN = Minute(DateTime)
dtmS = Second(DateTime)
dtmW = WeekDay(DateTime)
arrFW = Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
arrSW = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
arrFM = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
arrSM = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
Template = Replace(Template,"{Y}",dtmY)
Template = Replace(Template,"{y}",Right(dtmY,2))
Template = Replace(Template,"{M}",dtmM)
Template = Replace(Template,"{m}",Right("00"&dtmM,2))
Template = Replace(Template,"{ME}",arrFM(dtmM-1))
Template = Replace(Template,"{Me}",arrSM(dtmM-1))
Template = Replace(Template,"{D}",dtmD)
Template = Replace(Template,"{d}",Right("00"&dtmD,2))
Template = Replace(Template,"{H}",dtmH )
Template = Replace(Template,"{h}",Right("00"&dtmH ,2))
Template = Replace(Template,"{N}",dtmN)
Template = Replace(Template,"{n}",Right("00"&dtmN,2))
Template = Replace(Template,"{S}",dtmS)
Template = Replace(Template,"{s}",Right("00"&dtmS,2))
Template = Replace(Template,"{W}",arrFW(dtmW-1))
Template = Replace(Template,"{w}",arrSW(dtmW-1))
FormatTime = Template
End Function
%>