ASP显示时间问题,帮帮忙,跪求
这个代码显示的时分秒都是00是怎么回事?哪位好心人帮我看一下,急用<%FunctionFormat_Time(s_Time,n_Flag)Dimy,m,d,h,mi,sF...
这个代码显示的时分秒都是00是怎么回事?哪位好心人帮我看一下,急用
<%
Function Format_Time(s_Time, n_Flag)
Dim y, m, d, h, mi, s
Format_Time = ""
If IsDate(s_Time) = False Then Exit Function
y = cstr(year(s_Time))
m = cstr(month(s_Time))
If len(m) = 1 Then m = "0" & m
d = cstr(day(s_Time))
If len(d) = 1 Then d = "0" & d
h = cstr(hour(s_Time))
If len(h) = 1 Then h = "0" & h
mi = cstr(minute(s_Time))
If len(mi) = 1 Then mi = "0" & mi
s = cstr(second(s_Time))
If len(s) = 1 Then s = "0" & s
Select Case n_Flag
Case 1
Format_Time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
Case 2
Format_Time = y & "-" & m & "-" & d
Case 3
Format_Time = h & ":" & mi & ":" & s
Case 4
Format_Time = y & "年" & m & "月" & d & "日" & h & "时" & mi & "分"
Case 5
Format_Time = y & m & d
case 6
format_time= y & m & d & h & mi & s
case 7
format_time= y
case 8
format_time= m
case 9
format_time= d
End Select
End Function
response.write Format_Time(date(), 6)
%> 展开
<%
Function Format_Time(s_Time, n_Flag)
Dim y, m, d, h, mi, s
Format_Time = ""
If IsDate(s_Time) = False Then Exit Function
y = cstr(year(s_Time))
m = cstr(month(s_Time))
If len(m) = 1 Then m = "0" & m
d = cstr(day(s_Time))
If len(d) = 1 Then d = "0" & d
h = cstr(hour(s_Time))
If len(h) = 1 Then h = "0" & h
mi = cstr(minute(s_Time))
If len(mi) = 1 Then mi = "0" & mi
s = cstr(second(s_Time))
If len(s) = 1 Then s = "0" & s
Select Case n_Flag
Case 1
Format_Time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
Case 2
Format_Time = y & "-" & m & "-" & d
Case 3
Format_Time = h & ":" & mi & ":" & s
Case 4
Format_Time = y & "年" & m & "月" & d & "日" & h & "时" & mi & "分"
Case 5
Format_Time = y & m & d
case 6
format_time= y & m & d & h & mi & s
case 7
format_time= y
case 8
format_time= m
case 9
format_time= d
End Select
End Function
response.write Format_Time(date(), 6)
%> 展开
1个回答
展开全部
这是因为date()函数的返回值本身就只包含年月日,不包含时分秒的啊,你改成这样就正常了:
response.write Format_Time(now(), 6)
另外我把你的函数稍微简化了一下,看起来不会那么臃肿:
Function Format_Time(s_Time, n_Flag)
Dim y, m, d, h, mi, s
If Not IsDate(s_Time) Then Exit Function
y = year(s_Time)
m = right("0" & month(s_Time),2)
d = right("0" & day(s_Time),2)
h = right("0" & hour(s_Time),2)
mi = right("0" & minute(s_Time),2)
s = right("0" & second(s_Time),2)
Select Case n_Flag
Case 1
Format_Time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
Case 2
Format_Time = y & "-" & m & "-" & d
Case 3
Format_Time = h & ":" & mi & ":" & s
Case 4
Format_Time = y & "年" & m & "月" & d & "日" & h & "时" & mi & "分"
Case 5
Format_Time = y & m & d
case 6
format_time= y & m & d & h & mi & s
case 7
format_time= y
case 8
format_time= m
case 9
format_time= d
End Select
End Function
追问
我复制了你的代码,可还是显示20151214000000,这是怎么回事啊?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询