zoukankan      html  css  js  c++  java
  • ASP将日期格式化为需要的格式

    ASP将日期格式化为需要的格式


    '******************************
    '函数:FormatDate(DateAndTime, para)
    '参数:DateAndTime,要格式化的日期时间;para,样式。
    '作者:阿里西西
    '日期:2007/7/12
    '描述:将日期格式化为需要的格式
    '示例:<%=FormatDate(now(), 3)
    '******************************
    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  

  • 相关阅读:
    Lua 语言学习
    Unity EasyTouch官方案例学习
    Unity Dotween官方案例学习
    斗地主出牌规则
    C# XML文件读取
    斗地主项目总结
    C# 委托和事件
    C# 观察者模式
    消防法及相关法律法规(二)
    消防法及相关法律法规(一)
  • 原文地址:https://www.cnblogs.com/guo2001china/p/2232560.html
Copyright © 2011-2022 走看看