回 帖 发 新 帖 刷新版面

主题:asp动态网页中日期显示的问题,请各位帮帮忙。

在动态网页中(asp+access),网页显示时,有一列显示的是从数据库中读取的日期。我用的是<%=rs("sl_date")%>,但是遇到单月单日显示日期格式为“2006-1-1”,我想显示为“2006-01-01”,我该怎么办?我想了好几天了,也没解决,网上又搜不到解决方法。请高手帮一下忙,最好是有一段代码,谢谢!

回复列表 (共12个回复)

沙发

写个小函数,判断下
month(..)取月,day(..)取日
如果月小于10 加个零连接。。
。。。。

板凳


谢谢sjp2003,但是我是刚学的我不会写呀!您能帮我写一个吗,非常感谢!

3 楼

是这样吗?
dim yyyear,yymonth,yyday,ss
yyyear=year(rs("date"))
yymonth=month(rs("date"))
yyday=day(rs("date"))
if month(rs("date"))<10 then yymonth="0"&month(rs("date"))
if day(rs("date"))<10 then yyday="0"&day(rs("date"))
ss=yyyear&"-"&yymonth&"-"&yyday
然后将文本框里的值<%=rs("date")%>替换成<%response.write ss%>
这样也不行啊????

4 楼


“sjp2003”您在哪呢?帮人帮到底吧。这个问题是不是太简单了。但对于我来说,真是太难了。好几天都没睡好觉。在这里跪求了,再次表示感谢!谢谢。。。。

5 楼

function returntimestr(str)
 dim theyear,themonth,theday,thehour
  theyear=year(str)
  themonth=month(str)
    if themonth<10  then
     themonth=0&"themonth"
    end if
   theday=day(str)
    if theday<10 then
      theday=0&"theday"
    end if
   thehour=hour(str)
    if theday<10 then
      thehour=0&"thehour"
    end if
   thesecond=second(str)
     if thesecond<10 then
      thesecond=0&"thesecond"
     end if
  returntimestr=theyear&"-"&themonth&"-"&theday
end function
<%=returntimestr(rs(..))%>

6 楼


非常感谢!我再试试。

7 楼


“sjp2003”前辈,非常感谢您。我按您的做了,但是还是有问题。我是这样做的:<html>
<%
function returntimestr(str)
 dim theyear,themonth,theday,thehour
  theyear=year(str)
  themonth=month(str)
    if themonth<10  then
     themonth=0&"themonth"
    end if
   theday=day(str)
    if theday<10 then
      theday=0&"theday"
    end if
   thehour=hour(str)
    if theday<10 then
      thehour=0&"thehour"
    end if
   thesecond=second(str)
     if thesecond<10 then
      thesecond=0&"thesecond"
     end if
  returntimestr=theyear&"-"&themonth&"-"&theday
end function
%>
<head>
.......
然后在文本框里将<%=rs("dfs_date")%>替换成<%=returntimestr(rs("dfs_date"))%>  但是运行后,遇到月或日就显示英文0+月或0+日。如2006-0themonth-12,或者2006-11-0theday这是怎么回事?

8 楼


打错了,遇到“单个月”份或“单个日”就显示0+英文。

9 楼

用len()判断一下month和day,如果是一位就前面加个0

10 楼

不好意思,写错了点 
function returntimestr(str)
 dim theyear,themonth,theday,thehour
  theyear=year(str)
  themonth=month(str)
    if themonth<10  then
     themonth="0"&themonth
    end if
   theday=day(str)
    if theday<10 then
      theday="0"&theday
    end if
      returntimestr=theyear&"-"&themonth&"-"&theday
end function
%>这下可以了,刚测试过了 

我来回复

您尚未登录,请登录后再回复。点此登录或注册