1[转]asp格式化日期 最近写代码所用到的,贴出来大家分享,当然要谢谢那些前辈们,提供的一些好的方法
 2[转]asp格式化日期
 3[转]asp格式化日期<
 4[转]asp格式化日期' ============================================ 
 5[转]asp格式化日期' 格式化时间(显示) 
 6[转]asp格式化日期' 参数:n_Flag 
 7[转]asp格式化日期' 1:"yyyy-mm-dd hh:mm:ss" 
 8[转]asp格式化日期' 2:"yyyy-mm-dd" 
 9[转]asp格式化日期' 3:"hh:mm:ss" 
10[转]asp格式化日期' 4:"yyyy年mm月dd日" 
11[转]asp格式化日期' 5:"yyyymmdd" 
12[转]asp格式化日期' 6:"yyyymmddhhmmss" 
13[转]asp格式化日期' ============================================ 
14[转]asp格式化日期Function Format_Time(s_Time, n_Flag) 
15[转]asp格式化日期Dim y, m, d, h, mi, s 
16[转]asp格式化日期Format_Time = "" 
17[转]asp格式化日期If IsDate(s_Time) = False Then Exit Function 
18[转]asp格式化日期= cstr(year(s_Time)) 
19[转]asp格式化日期= cstr(month(s_Time)) 
20[转]asp格式化日期If len(m) = 1 Then m = "0" & m 
21[转]asp格式化日期= cstr(day(s_Time)) 
22[转]asp格式化日期If len(d) = 1 Then d = "0" & d 
23[转]asp格式化日期= cstr(hour(s_Time)) 
24[转]asp格式化日期If len(h) = 1 Then h = "0" & h 
25[转]asp格式化日期mi = cstr(minute(s_Time)) 
26[转]asp格式化日期If len(mi) = 1 Then mi = "0" & mi 
27[转]asp格式化日期= cstr(second(s_Time)) 
28[转]asp格式化日期If len(s) = 1 Then s = "0" & s 
29[转]asp格式化日期Select Case n_Flag 
30[转]asp格式化日期Case 1 
31[转]asp格式化日期' yyyy-mm-dd hh:mm:ss 
32[转]asp格式化日期Format_Time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s 
33[转]asp格式化日期Case 2 
34[转]asp格式化日期' yyyy-mm-dd 
35[转]asp格式化日期Format_Time = y & "-" & m & "-" & d 
36[转]asp格式化日期Case 3 
37[转]asp格式化日期' hh:mm:ss 
38[转]asp格式化日期Format_Time = h & ":" & mi & ":" & s 
39[转]asp格式化日期Case 4 
40[转]asp格式化日期' yyyy年mm月dd日 
41[转]asp格式化日期Format_Time = y & "" & m & "" & d & "" 
42[转]asp格式化日期Case 5 
43[转]asp格式化日期' yyyymmdd 
44[转]asp格式化日期Format_Time = y & m & d 
45[转]asp格式化日期case 6 
46[转]asp格式化日期'yyyymmddhhmmss 
47[转]asp格式化日期format_time= y & m & d & h & mi & s 
48[转]asp格式化日期End Select 
49[转]asp格式化日期End Function 
50[转]asp格式化日期%>
51[转]asp格式化日期
52[转]asp格式化日期<%=format_time(now,1)%>
53[转]asp格式化日期

当需要将长日期格式转换为短日期格式时,可以使用FormatDateTime 函数

FormatDateTime 函数
请参阅
FormatCurrency 函数 | FormatNumber 函数 | FormatPercent 函数
要求
版本2
返回表达式,此表达式已被格式化为日期或时间。

FormatDateTime(Date[, NamedFormat])
参数
Date
必选项。要被格式化的日期表达式。
NamedFormat
可选项。指示所使用的日期/时间格式的数值,如果省略,则使用 vbGeneralDate。
设置
NamedFormat 参数可以有以下值:

常数 值 描述
vbGeneralDate 0 显示日期和/或时间。如果有日期部分,则将该部分显示为短日期格式。如果有时间部分,则将该部分显示为长时间格式。如果都存在,则显示所有部分。
vbLongDate 1 使用计算机区域设置中指定的长日期格式显示日期。
vbShortDate 2 使用计算机区域设置中指定的短日期格式显示日期。
vbLongTime 3 使用计算机区域设置中指定的时间格式显示时间。
vbShortTime 4 使用 24 小时格式 (hh:mm) 显示时间。

说明
下面例子利用 FormatDateTime 函数把表达式格式化为长日期型并且把它赋给 MyDateTime:

Function GetCurrentDate
   'FormatDateTime 把日期型格式化为长日期型。
   GetCurrentDate = FormatDateTime(Date, 1)
End Function
要求
版本2

相关文章: