asp格式化日期时间格式的代码
程序员文章站
2022-10-27 20:29:14
' ============================================ ' 格式化时间(显示) ' 参数:n_flag...
' ============================================
' 格式化时间(显示)
' 参数:n_flag
' 1:"yyyy-mm-dd hh:mm:ss"
' 2:"yyyy-mm-dd"
' 3:"hh:mm:ss"
' 4:"yyyy年mm月dd日"
' 5:"yyyymmdd"
' ============================================
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
' yyyy-mm-dd hh:mm:ss
format_time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
case 2
' yyyy-mm-dd
format_time = y & "-" & m & "-" & d
case 3
' hh:mm:ss
format_time = h & ":" & mi & ":" & s
case 4
' yyyy年mm月dd日
format_time = y & "年" & m & "月" & d & "日"
case 5
' yyyymmdd
format_time = y & m & d
end select
end function
' 格式化时间(显示)
' 参数:n_flag
' 1:"yyyy-mm-dd hh:mm:ss"
' 2:"yyyy-mm-dd"
' 3:"hh:mm:ss"
' 4:"yyyy年mm月dd日"
' 5:"yyyymmdd"
' ============================================
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
' yyyy-mm-dd hh:mm:ss
format_time = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
case 2
' yyyy-mm-dd
format_time = y & "-" & m & "-" & d
case 3
' hh:mm:ss
format_time = h & ":" & mi & ":" & s
case 4
' yyyy年mm月dd日
format_time = y & "年" & m & "月" & d & "日"
case 5
' yyyymmdd
format_time = y & m & d
end select
end function
下一篇: JAVA数据结构之二叉树