[推荐]ASP格式化日期的函数(输出13种样式)

作者:网络 来源:佚名 更新时间:2008-01-17 03:12:56 点击:

'================================================
 '函数名:formatdate
 '作  用:格式化日期
 '参  数:dateandtime   ----原日期和时间
 '        para   ----日期格式
 '返回值:格式化后的日期
 '================================================
 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 & "日"
  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