海南世纪云图网络科技有限公司
咨询热线:400-822-8458 技术支持:0898-66754910 客户服务:0898-32183600

ASP 日期时间格式化函数(For VBScript )

发表于:2011-06-15 00:00:00来源:不懂戀愛魚兒人气:1993

<%@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}分{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}:分  
'   {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 
%> 

文章整理: 世纪云图  https://www.yuntop.cc/

以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

版权申明:本站文章部份来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!

特别注意:本站部份转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。

微信
网站建设
软件业务
网络营销
400电话