ASP格式化时间日期函数


ASP #时间 #日期 #函数2012-04-30 14:49
public function formatdt(dt, style)
'style=0 2000-10-10 下午 12:17:45
'style=1 2000-10-10 23:17:45
'style=2 2000-10-10 23:45
'style=3 00-10-10 23:45
'style=4 10-10 23:45
'style=5 2000-10-10
'style=6 00-10-10
'style=7 10-10
'style=8 23h-45m-45s
'style=9 20001010231745
'style=10 0510   上传图片
'style=11 05年10月10日
'style=12 05/10/12   上传图片
    dim nowdate, y, m, d, h, i, s, t, apm, hapm
    nowdate = dt
    y = year(nowdate)
    if len(y)=1 then y="0"&y
    m = month(nowdate)
    if len(m)=1 then m="0"&m
    d = day(nowdate)
    if len(d)=1 then d="0"&d
    h = hour(nowdate)
    if len(h)=1 then h="0"&h
    i = minute(nowdate)
    if len(i)=1 then i="0"&i
    s = second(nowdate)
    if len(s)=1 then s="0"&s
   if h > 12 then
        apm = "下午 "
        hapm = cstr(cint(h) mod 12)
   else
        apm = "上午 "
        hapm = h
   end if
    select case style
        case 0
            t = y & "-" & m & "-" & d & " " & apm & hapm & ":" & i & ":" & s
        case 1
            t = y & "-" & m & "-" & d & " " & h & ":" & i & ":" & s
        case 2
            t = y & "-" & m & "-" & d & " " & h & ":" & i
        case 3
            t = right(y, 2) & "-" & m & "-" & d & " " & h & ":" & i
        case 4
            t = m & "-" & d & " " & h & ":" & i
        case 5
            t = y & "-" & m & "-" & d
        case 6
            t = right(y, 2) & "-" & m & "-" & d
        case 7
            t = m & "-" & d
        case 8
            t = h & "h-" & i & "m-" & s &"s"
        case 9
            t = y & m & d & h & i & s
        case 10'上传
            t = right(y, 2) & m 
  case 11
   t = right(y, 2) & "年" & m & "月" & d & "日"
  case 12
   t = right(y, 2) & "/" & m & "/" & d
    end select
   
    formatdt = t
end function

相关文章

粤ICP备11097351号-1