分类: 系统运维
2010-04-17 23:06:11
将下面的代码复制保存到asp中就可以看到效果与调用方法
<%=now()%>
<%=Replace(Now(),":",":")%>
response.write formatdatetime(now,0)&"
"
response.write formatdatetime(now,1)&"
"
response.write formatdatetime(now,2)&"
"
response.write formatdatetime(now,3)&"
"
response.write formatdatetime(now,4)&"
"
%>
'月份转换到长英文
Function MonthToLongEN(TheMonth)
Dim mm
mm=split("January,February,March,April,May,June,July,August,September,October,November,December",",")
If IsNumeric(TheMonth) Then
MonthToLongEN = mm(TheMonth-1)
Else
MonthToLongEN = " "
End If
End Function
'月份转换到短英文
Function MonthToShortEN(TheMonth)
Dim mm
mm=split("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",",")
If IsNumeric(TheMonth) Then
MonthToShortEN = mm(TheMonth-1)
Else
MonthToShortEN = " "
End If
End Function
%>
获取当前月份,ASP输出:<%=MonthToCH(Month(now()))%>
获取当前月份,ASP输出:<%=MonthToLongEN(Month(now()))%>
获取当前月份,ASP输出:<%=MonthToShortEN(Month(now()))%>
<%
'================================================
'函数名:FormatDate
'作 用:格式化日期
'参 数:DateAndTime ----原日期和时间
' para ----日期格式
'返回值:格式化后的日期
'================================================
Public Function FormatDate(DateAndTime, para)
On Error Resume Next
Dim y, m, d, h, mi, s, strDateTime
FormatDate = DateAndTime
If Not IsNumeric(para) Then Exit Function
If Not IsDate(DateAndTime) Then Exit Function
y = CStr(Year(DateAndTime))
m = CStr(Month(DateAndTime))
If Len(m) = 1 Then m = "0" & m
d = CStr(Day(DateAndTime))
If Len(d) = 1 Then d = "0" & d
h = CStr(Hour(DateAndTime))
If Len(h) = 1 Then h = "0" & h
mi = CStr(Minute(DateAndTime))
If Len(mi) = 1 Then mi = "0" & mi
s = CStr(Second(DateAndTime))
If Len(s) = 1 Then s = "0" & s
Select Case para
Case "1"
'显示格式:09年07月06日 13:44
strDateTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
Case "2"
'显示格式:2009-07-06
strDateTime = y & "-" & m & "-" & d
Case "3"
'显示格式:2009/07/06
strDateTime = y & "/" & m & "/" & d
Case "4"
'显示格式:2009年07月06日
strDateTime = y & "年" & m & "月" & d & "日"
Case "5"
'显示格式:07-06 13:45
strDateTime = m & "-" & d & " " & h & ":" & mi
Case "6"
'显示格式:07/06
strDateTime = m & "/" & d
Case "7"
'显示格式:07月06日
strDateTime = m & "月" & d & "日"
Case "8"
'显示格式:2009年07月
strDateTime = y & "年" & m & "月"
Case "9"
'显示格式:2009-07
strDateTime = y & "-" & m
Case "10"
'显示格式:2009/07
strDateTime = y & "/" & m
Case "11"
'显示格式:09年07月06日 13:45
strDateTime = right(y,2) & "年" &m & "月" & d & "日 " & h & ":" & mi
Case "12"
'显示格式:09-07-06
strDateTime = right(y,2) & "-" &m & "-" & d
Case "13"
'显示格式:07-06
strDateTime = m & "-" & d
Case "14"
'显示格式:13:45
strDateTime = h & ":" & mi
Case Else
strDateTime = DateAndTime
End Select
FormatDate = strDateTime
End Function
%>
获取当前月份,ASP输出:<%=FormatDate(now(),13)%>
获取当前月份,ASP输出:<%=FormatDate(now(),11)%>