回 帖 发 新 帖 刷新版面

主题:时间显示问题

我想让时间显示成
2007-04-17的形式
但是 datetime 只能显示 2007-4-17

如果要显示成 2007-04-17的形式 是不是只能用varchar呢?

回复列表 (共17个回复)

11 楼

Dim strYear
Dim strMonth
Dim strDay

strYear=Right("0000"&Year(Now),4)
strMonth=Right("00"&Month(Now),2)
strDay=Right("00"&Day(Now),2)

Response.Write strYear&"-"&strMonth&"-"&strDay

'貌似这种写起来舒服些,不用那些格式函数。

12 楼

从系统获取的时间是这样写的
但是我是从数据库中读取的时间,就是这个我想不明白

<%   
  YTime=Year(怎么从数据库获取到这里?)   
  MTime=Month(怎么从数据库获取到这里?)   
  DTime=Day(怎么从数据库获取到这里?)   
       
  if   len(MTime)=1   then   
        Mtime="0"&MTime   
  end   if   
  if   len(DTime)=1   then   
        Dtime="0"&DTime   
  end   if   
  ldate   =   Ytime   &"-"&   Mtime   &"-"&   DTime   
    
  response.write   ldate   
  %>

13 楼

写个记录集获取啊

14 楼

<%
    function ldate
        YTime=Year(<%=rs("ltime")%>)   
          MTime=Month(<%=rs("ltime")%>)   
          DTime=Day(<%=rs("ltime")%>)   
    if  len(MTime)=1  then
        MTime="0"&MTime
    end if
    if  len(DTime)=1  then
        DTime="0"&DTime
    end if
%>
<%=ldate(rs("ltime"))%>



是这样吗?  我怎么感觉好象不对呢

15 楼

谢谢大家帮忙 弄出来了  都给大家加分喽
我把结果贴出来 以后大家参考 呵呵
<%   s=rs("lrrq")
        YTime=Year(s)   
          MTime=Month(s)   
          DTime=Day(s)   
    if  len(MTime)=1  then
        MTime="0"&MTime
    end if
    if  len(DTime)=1  then
        DTime="0"&DTime
    end if
    ldate   =   Ytime   &"-"&   Mtime   &"-"&   DTime 
    response.write ldate
%>

16 楼

MTime="0"&MTime
这种写法不行的。
最好是这样。
MTime=Right("00"&Time,2)
这样可以保证取到的值都是两位。如果按你那种方法的话,中间多一个判断,显得有些冗余。

17 楼

谢谢

我来回复

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