我想把日期的格式设置成这样的形式:“02/29/04”
该用哪条语句呢?
我帮你写了个函数来格式化日期
<% '//////////////////////////////////////////////////////////////////////////// '格式化时间字符串函数,Written by griefforyou '参数:varDate为时间字符串 '参数:Format参数为格式字符串,格式字符串中可以包含yyyy(四位数年份),yy(两位数年份) 'MM(长格式月份),M(短格式月份),dd(长格式日期),d(短格式日期) '//////////////////////////////////////////////////////////////////////////// Private Function FormatDate(varDate ,Format) Dim year ,shortyear Dim month , shortmonth Dim day , shortday Dim temp
If Not IsDate(varDate) Then Exit Function If Format="" then Format= "MM/dd/yy"
year = DatePart("yyyy", varDate) shortyear = Right(year, 2) shortmonth = DatePart("M", varDate) If Len(shortmonth) = 2 Then month = shortmonth Else month = "0" & shortmonth End If shortday = DatePart("d", varDate) If Len(shortday) = 2 Then day = shortday Else day = "0" & shortday End If temp = Replace(Format, "yyyy", year) temp = Replace(temp, "yy", shortyear) temp = Replace(temp, "MM", month) temp = Replace(temp, "M", shortmonth) temp = Replace(temp, "dd", day) temp = Replace(temp, "d", shortday) FormatDate = temp End Function
%> 函数使用示例:<br> Now 当前日期为 <%=Now%><br> FormatDate(Now,"") 返回值为 "<%=FormatDate(Now,"")%>" (默认Format参数为"MM/dd/yy")<br> FormatDate(Now,"MM/dd/yy") 返回值为 "<%=FormatDate(Now,"MM/dd/yy")%>" <br> FormatDate(Now,"M/d/yy") 返回值为 "<%=FormatDate(Now,"M/d/yy")%>" <br> FormatDate(Now,"yyyy-MM-dd") 返回值为 "<%=FormatDate(Now,"yyyy-MM-dd")%>"<br> FormatDate(Now,"MM/dd/yyyy") 返回值为 "<%=FormatDate(Now,"MM/dd/yyyy")%>"<br> FormatDate(Now,"yyyy/M/d") 返回值为 "<%=FormatDate(Now,"yyyy/M/d")%>"<br> FormatDate(Now,"yyyy-M-d") 返回值为 "<%=FormatDate(Now,"yyyy-M-d")%>"<br>
输出结果如下:
[此贴子已经被作者于2004-09-05 14:18:04编辑过]