当前位置: 代码迷 >> ASP >> 经过ASP代码实现时间格式化
  详细解决方案

经过ASP代码实现时间格式化

热度:10016   发布时间:2013-02-26 00:00:00.0
通过ASP代码实现时间格式化
通过ASP代码实现时间格式化

下面试试先的代码
Function Format_DateTime(S_DateTime,I_Format)
Dim y, m, d, h, mi, s
Format_DateTime = ""
If IsDate(S_DateTime) = False Then Exit Function
y = cstr(year(S_DateTime))
m = cstr(month(S_DateTime))
If len(m) = 1 Then m = "0" & m
d = cstr(day(S_DateTime))
If len(d) = 1 Then d = "0" & d
h = cstr(hour(S_DateTime))
If len(h) = 1 Then h = "0" & h
mi = cstr(minute(S_DateTime))
If len(mi) = 1 Then mi = "0" & mi
s = cstr(second(S_DateTime))
If len(s) = 1 Then s = "0" & s
Select Case I_Format
Case 0
Format_DateTime = m & "-" & d
Case 1
' yyyy-mm-dd hh:mm:ss
Format_DateTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
Case 2
' yyyy-mm-dd
Format_DateTime = y & "-" & m & "-" & d
Case 3
' hh:mm:ss
Format_DateTime = h & ":" & mi & ":" & s
Case 4
' yyyy年mm月dd日
Format_DateTime = y & "年" & m & "月" & d & "日"
Case 5
' yyyymmdd
Format_DateTime = y & m & d
Case 6
' yyyy-mm-dd hh:mm
Format_DateTime = y & "-" & m & "-" & d & " " & h & ":" & mi
End Select
End Function

下面举例
Format_DateTime(Now(),0)

转至:
http://www.xszlo.com/article/2012-11-29/7536
  相关解决方案