ASP 格式化日期 [英] ASP formatting date
本文介绍了ASP 格式化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在尝试让 ASP 中的日期以特定格式 (yyyymmdd) 显示.这是我迄今为止尝试过的,但没有运气.任何帮助表示赞赏.谢谢
Hello there I'm trying to get a date in ASP to show up in a particular format (yyyymmdd). This is what I've tried so far but no luck. Any help is appreciated. Thanks
<tr>
<td><b>Call Date</b></td>
<% for i = -6 to 0 %>
<td align=center>
<a href="20a.asp?cldate=<% response.write(DateTime.Date()+i.ToString("yyyyMMdd")) %>" target="_blank">X</a>
</td>
<% Next %>
</tr>
推荐答案
您可以使用以下功能:
Year(Now) '' Year in 4 digits
Month(Now) '' Month without leading zero
Day(Now) '' Day of the month without leading zero
DateAdd("d", <numofdays>, Now) '' add a number of days to your date
在此处了解有关这些(和其他日期函数)函数的更多信息.
Read more about these (and other date functions) functions here.
如果需要添加前导零:
function addLeadingZero(value)
addLeadingZero = value
if value < 10 then
addLeadingZero = "0" & value
end if
end function
你的例子是:
Dim today, myDate
today = Now
for i = -6 to 0
myDate = DateAdd("d", i, today)
response.write "<a href=""20a.asp?cldate=" & Year(myDate) & addLeadingZero(Month(myDate)) & addLeadingZero(Day(myDate)) & """ target=""_blank"">X</a>"
next
这篇关于ASP 格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文