Asp时间/日期转换格式化函数

ASP程序在显示时间的时候,如果是短格式时间如2011/9/10显示出来的日期长度不一,影响排版视觉,通过ASP时间/日期格式化函数formatdate,可以解决这一问题。
asp时间/日期格式化函数

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 else
strdatetime = dateandtime
end select
formatdate = strdatetime
end function

转载请注明 :IT樵客

此条目发表在 程序设计 分类目录。将固定链接加入收藏夹。

关于 logger

2010年网络规划设计师证书寻挂靠!

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>