安徽教育出版社怎么样:如何显示时间-asp

来源:百度文库 编辑:神马品牌网 时间:2024/05/07 10:02:28
" <%=year(rs("时间"))&"-"&month(rs("时间"))&"-"&day(rs("时间"))%> "
这句代码显示的就是日期.样式:12月5日就是"2006-12-5"1月15日就是"2006-1-15".我就想问问大家,如何当月份和日期为单数时,在前面加0.例如:12月5日就是"2006-12-05",1月15日就是"2006-01-15".在此先谢过了.

请写明具体代码

建议用用len()函数比较好。

如果你存储的是字符型那If theMonth<10 Then 就会也错

建议这样做:

years=year(rs("时间"))

months=month(rs("时间"))

days=day(rs("时间"))

if len(months)=1 then
months="0"&months
end if

if len(days)=1 then
days="0"&days
end if

response.write "时间:"&years&"-"&months&"-"&days

这样就不会出错了。

Function getFullDate(theDate)
If Not isDate(theDate) Then '如果参数不是日期格式,则将参数设成当前日期
theDate=Now
End If
Dim theYear,theMonth,theDay
theYear=Year(theDate)
theMonth=Month(theDate)
theDay=Day(theDay)
If theMonth<10 Then
theMonth="0"&theMonth
End If
If theDay<10 Then
theDay="0"&theDay
End If
getFullDate=theYear&"-"&theMonth&"-"&theDay '在这里可以进行自定义显示格式了...^_^
End Function

Response.Write getFullDate(Now)

用JavaScript函数或ASP程序控制