当前位置:编程学习 > asp >>

在ASP中按指定参数格式化显示时间的函数

<%
'该函数作用:按指定参数格式化显示时间。
'numformat=1:将时间转化为yyyy-mm-dd hh:nn格式。
'numformat=2:将时间转化为yyyy-mm-dd格式。
'numformat=3:将时间转化为hh:nn格式。
'numformat=4:将时间转化为yyyy年mm月dd日 hh时nn分格式。
'numformat=5:将时间转化为yyyy年mm月dd日格式。
'numformat=6:将时间转化为hh时nn分格式。
'numformat=7:将时间转化为yyyy年mm月dd日 星期×格式。
'numformat=8:将时间转化为yymmdd格式。
'numformat=9:将时间转化为mmdd格式。
function formatdate(shijian,numformat)
dim ystr,mstr,dstr,hstr,nstr '变量含义分别为年字符串,月字符串,日字符串,时字符串,分字符串

if isnull(shijian) then
numformat=0
else
ystr=DatePart("yyyy",shijian)

if DatePart("m",shijian)>9 then
mstr=DatePart("m",shijian)
else
mstr="0"&DatePart("m",shijian)
end if

if DatePart("d",shijian)>9 then
dstr=DatePart("d",shijian)
else
dstr="0"&DatePart("d",shijian)
end if

if DatePart("h",shijian)>9 then
hstr=DatePart("h",shijian)
else
hstr="0"&DatePart("h",shijian)
end if

if DatePart("n",shijian)>9 then
nstr=DatePart("n",shijian)
else
nstr="0"&DatePart("n",shijian)
end if
end if

select case numformat
case 0
formatdate=""
case 1
formatdate=ystr&"-"&mstr&"-"&dstr&" "&hstr&":"&nstr
case 2
formatdate=ystr&"-"&mstr&"-"&dstr
case 3
formatdate=hstr&":"&nstr
case 4
补充:asp教程,高级应用
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,