海南(nán)世紀雲圖網絡科技有限公司
咨詢熱線:400-822-8458 客戶服務:0898-32183600

ASP 日期時間格式化函數(For VBScript )

發表于: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 
%> 

文章整理: 世紀雲圖  /

以上信息與文章正文是不可分(fēn)割的一(yī)部分(fēn),如果您要轉載本文章,請保留以上信息,謝謝!

版權申明:本站文章部份來自網絡,如有侵權,請聯系我(wǒ)(wǒ)們,我(wǒ)(wǒ)們收到後立即删除,謝謝!

特别注意:本站部份轉載文章言論不代表本站觀點,本站所提供的攝影照片,插畫,設計作品,如需使用,請與原作者聯系,版權歸原作者所有。

微信
網站建設
軟件業務
網絡營銷
400電(diàn)話(huà)