您的位置:首页 > 编程语言 > ASP

ASP格式化日期的函数(输出13种样式)

2008-11-27 15:54 295 查看
<IFRAME name=google_ads_frame marginWidth=0 marginHeight=0 src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-4490194096475053&dt=1227772423765&lmt=1226285564&prev_slotnames=1891601125&output=html&slotname=3685991503&correlator=1227772423734&url=http%3A%2F%2Fwww.corange.cn%2Farchives%2F2008%2F09%2F1639.html&ea=0&ref=http%3A%2F%2Fwww.corange.cn%2Fhtml%2Fcorange__94.html&frm=0&ga_vid=2091876339.1227189135&ga_sid=1227772069&ga_hid=2049062656&ga_fc=true&flash=9.0.124.0&u_h=768&u_w=1024&u_ah=715&u_aw=1024&u_cd=32&u_tz=480&u_java=true&dtd=31" frameBorder=0 width=300 scrolling=no height=250 allowTransparency></IFRAME>'函数名:FormatDate
'作 用:格式化日期
'参 数:DateAndTime ----原日期和时间
' para ----日期格式
'返回值:格式化后的日期
'================================================
Public Function FormatDate(DateAndTime, para)
On Error Resume Next
Dim y, m, d, h, mi, s, strDateTime
FormatDate = DateAndTime
If Not IsNumeric(para) Then Exit Function
If Not IsDate(DateAndTime) Then Exit Function
y = CStr(Year(DateAndTime))
m = CStr(Month(DateAndTime))
If Len(m) = 1 Then m = "0" & m
d = CStr(Day(DateAndTime))
If Len(d) = 1 Then d = "0" & d
h = CStr(Hour(DateAndTime))
If Len(h) = 1 Then h = "0" & h
mi = CStr(Minute(DateAndTime))
If Len(mi) = 1 Then mi = "0" & mi
s = CStr(Second(DateAndTime))
If Len(s) = 1 Then s = "0" & s
Select Case para
Case "1"
strDateTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
Case "2"
strDateTime = y & "-" & m & "-" & d
Case "3"
strDateTime = y & "/" & m & "/" & d
Case "4"
strDateTime = y & "年" & m & "月" & d & "日"
Case "5"
strDateTime = m & "-" & d & " " & h & ":" & mi
Case "6"
strDateTime = m & "/" & d
Case "7"
strDateTime = m & "月" & d & "日"
Case "8"
strDateTime = y & "年" & m & "月"
Case "9"
strDateTime = y & "-" & m
Case "10"
strDateTime = y & "/" & m
Case "11"
strDateTime = right(y,2) & "-" &m & "-" & d & " " & h & ":" & mi
Case "12"
strDateTime = right(y,2) & "-" &m & "-" & d
Case "13"
strDateTime = m & "-" & d
Case Else
strDateTime = DateAndTime
End Select
FormatDate = strDateTime
End Function
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp function