精美而实用的网站,关注web编程技术、网站运营、SEO推广,让您轻松愉快的学习

ASP里面的日期函数格式有时候不是我们想要的格式怎么办?青岛星网下面跟大家分享一个ASP日期格式化函数,支持13种不同的时间样式哦。

ASP日期格式化函数(支持13中格式)

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
Tags:ASP 日期 函数