当前位置:asp编程网>技术教程>Asp教程>  正文

格式化日期函数(16种)

2010-10-18 15:07:28   来源:    作者:佚名   浏览量:2077   收藏
<%
'=========格式化日期==================

Function FormatDate(DateStr, Types)
    Dim DateString
    If IsDate(DateStr) = False Then
        DateString = ""
    End If
    Select Case Types
        Case "1"
            DateString = Year(DateStr)"-"&Month(DateStr)"-"&Day(DateStr)
        Case "2"
            DateString = Year(DateStr)"."&Month(DateStr)"."&Day(DateStr)
        Case "3"
            DateString = Year(DateStr)"/"&Month(DateStr)"/"&Day(DateStr)
        Case "4"
            DateString = Month(DateStr)"/"&Day(DateStr)"/"&Year(DateStr)
        Case "5"
            DateString = Day(DateStr)"/"&Month(DateStr)"/"&Year(DateStr)
        Case "6"
            DateString = Month(DateStr)"-"&Day(DateStr)"-"&Year(DateStr)
        Case "7"
            DateString = Month(DateStr)"."&Day(DateStr)"."&Year(DateStr)
        Case "8"
            DateString = Month(DateStr)"-"&Day(DateStr)
        Case "9"
            DateString = Month(DateStr)"/"&Day(DateStr)
        Case "10"
            DateString = Month(DateStr)"."&Day(DateStr)
        Case "11"
            DateString = Month(DateStr)"月"&Day(DateStr)"日"
        Case "12"
            DateString = Day(DateStr)"日"&Hour(DateStr)"时"
        Case "13"
            DateString = Day(DateStr)"日"&Hour(DateStr)"点"
        Case "14"
            DateString = Hour(DateStr)"时"&Minute(DateStr)"分"
        Case "15"
            DateString = Hour(DateStr)":"&Minute(DateStr)
        Case "16"
            DateString = Year(DateStr)"年"&Month(DateStr)"月"&Day(DateStr)"日"
        Case Else
            DateString = DateStr
    End Select
    FormatDate = DateString
End Function
%>
(鼠标移到代码上去,在代码的顶部会出现四个图标,第一个是查看源代码,第二个是复制代码,第三个是打印代码,第四个是帮助)



测试:

<%
For i = 1 To 16
    Response.Write(""&i"、"&FormatDate(Now(), ""&i"")"")"<br>"
Next
%>
(鼠标移到代码上去,在代码的顶部会出现四个图标,第一个是查看源代码,第二个是复制代码,第三个是打印代码,第四个是帮助)

 

最后输出的形式为:
1、2009-5-8
2、2009.5.8
3、2009/5/8
4、5/8/2009
5、8/5/2009
6、5-8-2009
7、5.8.2009
8、5-8
9、5/8
10、5.8
11、5月8日
12、8日15时
13、8日15点
14、15时39分
15、15:39
16、2009年5月8日



关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网