格式化输出
1,2010-10-10 00:00:00 2,2010-10-10 3,2010/10/10 4,2010年10月10 00小时00分钟00秒 5,10-10 00:00:00 6,10/10 7,10月10日 其他变换根据程序要自行添加即可- '格式化时间函数
- public function formatdate(dateandtime,para)
- on error resume next
- dim y, m, d, h, mi, s, strdatetime
- formatdate = dateandtime
- if not isnumeric(para) then exit function
- if not isdate(dateandtime) then exit function
- y = cstr(year(dateandtime))
- m = cstr(month(dateandtime))
- if len(m) = 1 then m = "0" & m
- d = cstr(day(dateandtime))
- if len(d) = 1 then d = "0" & d
- h = cstr(hour(dateandtime))
- if len(h) = 1 then h = "0" & h
- mi = cstr(minute(dateandtime))
- if len(mi) = 1 then mi = "0" & mi
- s = cstr(second(dateandtime))
- if len(s) = 1 then s = "0" & s
- select case para
- case "1"
- strdatetime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
- case "2"
- strdatetime = y & "-" & m & "-" & d
- case "3"
- strdatetime = y & "/" & m & "/" & d
- case "4"
- strdatetime = y & "年" & m & "月" & d & "日 " & h & ":" & mi & ":" & s
- case "5"
- strdatetime = m & "-" & d & " " & h & ":" & mi
- case "6"
- strdatetime = m & "/" & d
- case "7"
- strdatetime = m & "月" & d & "日"
- case "8"
- strdatetime = y & "年" & m & "月"
- case "9"
- strdatetime = y & "-" & m
- case "10"
- strdatetime = y & "/" & m
- case "11"
- strdatetime = right(y,2) & "-" &m & "-" & d & " " & h & ":" & mi
- case "12"
- strdatetime = right(y,2) & "-" &m & "-" & d
- case "13"
- strdatetime = m & "-" & d
- case else
- strdatetime = dateandtime
- end select
- formatdate = strdatetime
- end function