zoukankan      html  css  js  c++  java
  • ASP日期格式化函数

    Public Function GetFormatDate(DateAndTime, para)
    On Error Resume Next
    Dim y, m, d, h, mi, s, strDateTime
    GetFormatDate = 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"
    '显示格式:09年07月06日 13:44 2009-07-06 13:45:00
    strDateTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
    Case "2"
    '显示格式:2009-07-06
    strDateTime = y & "-" & m & "-" & d
    Case "3"
    '显示格式:2009/07/06
    strDateTime = y & "/" & m & "/" & d
    Case "4"
    '显示格式:2009年07月06日
    strDateTime = y & "年" & m & "月" & d & "日"
    Case "5"
    '显示格式:07-06 13:45
    strDateTime = m & "-" & d & " " & h & ":" & mi
    Case "6"
    '显示格式:07/06
    strDateTime = m & "/" & d
    Case "7"
    '显示格式:07月06日
    strDateTime = m & "月" & d & "日"
    Case "8"
    '显示格式:2009年07月
    strDateTime = y & "年" & m & "月"
    Case "9"
    '显示格式:2009-07
    strDateTime = y & "-" & m
    Case "10"
    '显示格式:2009/07
    strDateTime = y & "/" & m
    Case "11"
    '显示格式:09年07月06日 13:45
    strDateTime = right(y,2) & "年" &m & "月" & d & "日 " & h & ":" & mi
    Case "12"
    '显示格式:09-07-06
    strDateTime = right(y,2) & "-" &m & "-" & d
    Case "13"
    '显示格式:07-06
    strDateTime = m & "-" & d
    Case "14"
    '显示格式:13:45
    strDateTime = h & ":" & mi
    Case Else
    strDateTime = DateAndTime
    End Select
    GetFormatDate = strDateTime
    End Function

    '例:

    Response.write GetFormatDate(now(), 2)

  • 相关阅读:
    windows 按时自动化任务
    Linux libusb 安装及简单使用
    Linux 交换eth0和eth1
    I.MX6 GPS JNI HAL register init hacking
    I.MX6 Android mmm convenient to use
    I.MX6 GPS Android HAL Framework 调试
    Android GPS GPSBasics project hacking
    Python windows serial
    【JAVA】别特注意,POI中getLastRowNum() 和getLastCellNum()的区别
    freemarker跳出循环
  • 原文地址:https://www.cnblogs.com/mazey/p/6503510.html
Copyright © 2011-2022 走看看