ASP中时间格式问题

来源:百度知道 编辑:UC知道 时间:2024/05/27 04:56:53
Access中newstime字段将数据类型设置日期/时间,格式设置为yyyy-mm-dd,如有一行记录为2007-01-02,但在如下调用:
response.Write(rs("newstime"))
结果却显示为2007-1-2。问题是,如何显示为2007-01-02?看到有人写一函数,使用split函数分割为年、月、日,若月、日为一位数则前加零,然后返回转换过的日期。必须要写一个函数来实现吗?有没有其他实现的方法?

用判断语句,<%if len(month(rs("newstime")))=1 then
response.write 0&month(rs("newstime"))
end if%>

关注~

ASP没有现成的函数吧,这个是我写的函数:
这样调用:response.Write(getdatestr(rs("newstime")))

function getdatestr(s)
getdatestr=""
if dstr="" or not isdate(s) then
exit function
end if
dim y,m,d
y=year(s)
m=month(s)
d=day(s)
if m<10 then m="0"&m
if d<10 then d="0"&d
getdatestr=y&"-"&m&"-"&d
end function