01
<%
02
'=========格式化日期==================
03
04
Function
FormatDate(DateStr, Types)
05
Dim
DateString
06
If
IsDate(DateStr) =
False
Then
07
DateString =
""
08
End
If
09
Select
Case
Types
10
Case
"1"
11
DateString = Year(DateStr)
"-"
&Month(DateStr)
"-"
&Day(DateStr)
12
Case
"2"
13
DateString = Year(DateStr)
"."
&Month(DateStr)
"."
&Day(DateStr)
14
Case
"3"
15
DateString = Year(DateStr)
"/"
&Month(DateStr)
"/"
&Day(DateStr)
16
Case
"4"
17
DateString = Month(DateStr)
"/"
&Day(DateStr)
"/"
&Year(DateStr)
18
Case
"5"
19
DateString = Day(DateStr)
"/"
&Month(DateStr)
"/"
&Year(DateStr)
20
Case
"6"
21
DateString = Month(DateStr)
"-"
&Day(DateStr)
"-"
&Year(DateStr)
22
Case
"7"
23
DateString = Month(DateStr)
"."
&Day(DateStr)
"."
&Year(DateStr)
24
Case
"8"
25
DateString = Month(DateStr)
"-"
&Day(DateStr)
26
Case
"9"
27
DateString = Month(DateStr)
"/"
&Day(DateStr)
28
Case
"10"
29
DateString = Month(DateStr)
"."
&Day(DateStr)
30
Case
"11"
31
DateString = Month(DateStr)
"月"
&Day(DateStr)
"日"
32
Case
"12"
33
DateString = Day(DateStr)
"日"
&Hour(DateStr)
"時"
34
Case
"13"
35
DateString = Day(DateStr)
"日"
&Hour(DateStr)
"點"
36
Case
"14"
37
DateString = Hour(DateStr)
"時"
&Minute(DateStr)
"分"
38
Case
"15"
39
DateString = Hour(DateStr)
":"
&Minute(DateStr)
40
Case
"16"
41
DateString = Year(DateStr)
"年"
&Month(DateStr)
"月"
&Day(DateStr)
"日"
42
Case
Else
43
DateString = DateStr
44
End
Select
45
FormatDate = DateString
46
End
Function
47
%>
(鼠標移到代碼上去,在代碼的頂部會出現四個圖標,第一個是查看源代碼,第二個是復制代碼,第三個是打印代碼,第四個是幫助)
測試:
1
<%
2
For
i = 1
To
16
3
Response.Write(
""
&i
"、"
&FormatDate(Now(),
""
&i
""
)
""
)
"<br>"
4
Next
5
%>
(鼠標移到代碼上去,在代碼的頂部會出現四個圖標,第一個是查看源代碼,第二個是復制代碼,第三個是打印代碼,第四個是幫助)
最後輸出的形式為:
1、2009-5-8
2、2009.5.8
3、2009/5/8
4、5/8/2009
5、8/5/2009
6、5-8-2009
7、5.8.2009
8、5-8
9、5/8
10、5.8
11、5月8日
12、8日15時
13、8日15點
14、15時39分
15、15:39
16、2009年5月8日