ASP新闻列表中,如何才能只显示日期,不显示时间呀? 20
<ulclass="news"><%Setrs=server.CreateObject("adodb.recordset")exec="selecttop9*fromne...
<ul class="news">
<%
Set rs = server.CreateObject("adodb.recordset")
exec = "select top 9 * from news where category=1 order by id desc "
rs.Open exec, conn, 1, 1
If rs.EOF And rs.bof Then
response.Write("暂无新闻!")
response.End()
End If
Do While Not rs.EOF
response.Write("<li><span class=""data"">"& left(rs("data"),10)&"</span><a href=""news_view.asp?id=" & rs("id") & """>" & Left(rs("title"),20) & "</a></li>")
rs.movenext
Loop
%> 展开
<%
Set rs = server.CreateObject("adodb.recordset")
exec = "select top 9 * from news where category=1 order by id desc "
rs.Open exec, conn, 1, 1
If rs.EOF And rs.bof Then
response.Write("暂无新闻!")
response.End()
End If
Do While Not rs.EOF
response.Write("<li><span class=""data"">"& left(rs("data"),10)&"</span><a href=""news_view.asp?id=" & rs("id") & """>" & Left(rs("title"),20) & "</a></li>")
rs.movenext
Loop
%> 展开
2个回答
展开全部
可以使用这种方法来显示日期
[<%=year(rs("data"))%>-<%=month(rs("data"))%>-<%=day(rs("data"))%>]
但是由于月和日有时是一位数,有时是两位数,可能会造成排版上的不美观。可以使用以下方法强制转为两位数
<%
response.Write "["
response.Write year(rs("publictime"))
response.Write "-"
vmonth=len(month(rs("publictime")))
if vmonth=1 then
response.Write "0"
response.Write month(rs("publictime"))
else
response.Write day(rs("publictime"))
end if
response.Write "-"
vday=len(day(rs("publictime")))
if vday=1 then
response.Write "0"
response.Write day(rs("publictime"))
response.Write "]"
else
response.Write day(rs("publictime"))
response.Write "]"
end if
%>
当然还有另一种方法,我在此只提供一种思路。“年”永远是四位,出问题的只有月和日。可以把所有的月和日变为“0+月/日”这样一来,所有的月或日都大于等于两位数了。然后再从右边取两位
[<%=year(rs("data"))%>-<%=month(rs("data"))%>-<%=day(rs("data"))%>]
但是由于月和日有时是一位数,有时是两位数,可能会造成排版上的不美观。可以使用以下方法强制转为两位数
<%
response.Write "["
response.Write year(rs("publictime"))
response.Write "-"
vmonth=len(month(rs("publictime")))
if vmonth=1 then
response.Write "0"
response.Write month(rs("publictime"))
else
response.Write day(rs("publictime"))
end if
response.Write "-"
vday=len(day(rs("publictime")))
if vday=1 then
response.Write "0"
response.Write day(rs("publictime"))
response.Write "]"
else
response.Write day(rs("publictime"))
response.Write "]"
end if
%>
当然还有另一种方法,我在此只提供一种思路。“年”永远是四位,出问题的只有月和日。可以把所有的月和日变为“0+月/日”这样一来,所有的月或日都大于等于两位数了。然后再从右边取两位
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询