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)

  • 相关阅读:
    简单自定义控件在view下可以运行在传统模式下运行显示空白
    symbian菜单2运行时更换菜单实现右键菜单功能
    得到文件路径信息 TParse
    Symbian菜单:创建一个最简单的菜单
    RFs 目录操作
    作品[RFileRead/WriteStream 练习] for s60 fp2
    对话框的练习
    文件浏览工具s60第二版
    转描述符
    得到驱动器信息
  • 原文地址:https://www.cnblogs.com/mazey/p/6503510.html
Copyright © 2011-2022 走看看