格式化输出日期时间新版本[VBS]

时间:2016-09-20 ┊ 阅读:6,970 次 ┊ 标签: 开发 , 编程 , 设计

格式化输出日期时间新版本:
'format the datetime string, overload the internal function FormatDateTime
代码如下:

Function FormatDateTime(dateTime, NamedFormat)
    Dim y, m, d, h, n, s
    FormatDateTime = ""
    If IsDate(dateTime) = False Then
        dateTime = Now
    End If
    y = Cstr(Year(dateTime))
    m = Cstr(Month(dateTime))
    If Len(m) = 1 Then
        m = "0" & m
    End If
    d = Cstr(Day(dateTime))
    If Len(d) = 1 Then
        d = "0" & d
    End If
    h = Cstr(Hour(dateTime))
    If Len(h) = 1 Then
        h = "0" & h
    End If
    n = Cstr(Minute(dateTime))
    If Len(n) = 1 Then
        n = "0" & n
    End If
    s = Cstr(Second(dateTime))
    If Len(s) = 1 Then
        s = "0" & s
    End If
    Select Case NamedFormat
        Case 0
            ' yyyymmdd
            FormatDateTime = y & m & d
        Case 1
            ' yyyy-mm-dd hh:mm:ss
            FormatDateTime = y & "-" & m & "-" & d & " " & h & ":" & n & ":"  & s
        Case 2
            ' yyyy-mm-dd
            FormatDateTime = y & "-" & m & "-" & d
        Case 3
            ' hh:mm:ss
            FormatDateTime = h & ":" & n & ":" & s
        Case 4
            'yyyy-mm-dd hh.mm.ss
            FormatDateTime = y & "-" & m & "-" & d & " " & h & "." & n & "."  & s
        Case 5
            'mmm ddth, e.g. Sep 13th
            Select Case m
                Case 01 m = "Jan"
                Case 02 m = "Feb"
                Case 03 m = "Mar"
                Case 04 m = "Apr"
                Case 05 m = "May"
                Case 06 m = "Jun"
                Case 07 m = "Jul"
                Case 08 m = "Aug"
                Case 09 m = "Sep"
                Case 10 m = "Oct"
                Case 11 m = "Nov"
                Case 12 m = "Dec"
            End Select
            Select Case d
                Case 01, 21, 31 d = d + "st"
                Case 02, 22 d = d + "nd"
                Case 03, 23 d = d + "rd"
                Case else d = d + "th"
            End Select
            FormatDateTime = m & " " & d
    End Select
End Function

文章评论

添加新评论

温馨提醒:如果您是第一次在本站留言,需要审核后才能显示哦!

相关文章

ValueError: Error getting directory

ValueError: Error getting directory

ssl证书过期了 明明自动renew的 然后看log已经好久没更新成功了 查半天是当前server不信任远程连接 只能自己改代码 报错: 21-12-17 13:01:11 Generate CSR...amkevin.csr amkevin.csr generated. /home/www...
阅读全文>>
Introduction to ILE RPG Activation Groups

Introduction to ILE RPG Activation Groups

Learn how activation groups can help your ILE RPG programs run more efficiently, how to specify the type of group to use, and closing and reclaimin...
阅读全文>>
popup.js怎么和content.js通信?[JQuery]

popup.js怎么和content.js通信?[JQuery]

这两天为了实现一个谷歌浏览器插件功能,研究了半天怎么让插件来改特定网页里的特定字段的值,而这个值又来自popup的网页预先设定,下一步实现动态加载,可以让更多组实现便利。 目的很简单,我们有一个list,需要填到网页的某个字段,当然是好几个,这些值是设定好的,网页系统我们没法改,input想...
阅读全文>>
如何绕过登录抓取js动态加载网页数据[Python]

如何绕过登录抓取js动态加载网页数据[Python]

今天经历了一翻折腾,把一个需要登录网站并js动态加载的数据一一给抓下来了。 首先,登录时有cookie,我们需要把cookie保存下来,用urllib2构建request时加入header信息,这时还多了一点,虚构了浏览器信息,让服务器以为是正常的浏览器发起的请求,这样可以绕过简单的反爬虫策略...
阅读全文>>
终于用上了专业版的PyCharm含激活方法链接[Python]

终于用上了专业版的PyCharm含激活方法链接[Python]

就直接上图片吧: 激活方法链接:https://www.cnblogs.com/pupilheart/p/9734124.html
阅读全文>>