asp 将日期格式化为需要的格式
程序员文章站
2023-08-24 12:57:53
<% '****************************** '函数:formatdate(dateandtime, para) '参数:datea...
<%
'******************************
'函数:formatdate(dateandtime, para)
'参数:dateandtime,要格式化的日期时间;para,样式。
'作者:阿里西西
'日期:2007/7/12
'描述:将日期格式化为需要的格式
'示例:<%=formatdate(now(), 3)%>
'******************************
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
%>
'******************************
'函数:formatdate(dateandtime, para)
'参数:dateandtime,要格式化的日期时间;para,样式。
'作者:阿里西西
'日期:2007/7/12
'描述:将日期格式化为需要的格式
'示例:<%=formatdate(now(), 3)%>
'******************************
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 快速执行动态网页
下一篇: PHP文件读取功能的应用实例