日期格式功能将日期显示为“ 2014年1月13日” [英] date format function to display date as "Jan 13 2014"

查看:153
本文介绍了日期格式功能将日期显示为“ 2014年1月13日”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VBScript中是否有任何功能以 mmm-dd-yyyy 格式显示日期?
例如今天的日期为 2014年1月22日

Is there any function to display date in the format mmm-dd-yyyy in VBScript? eg. today's date as Jan 22 2014?

我尝试使用函数

FormatDateTime(Now(), 2)

我将其作为 2014年1月16日 c 。

I got it as 16 January 2014.

是否有任何函数/格式将其作为 2014年1月16日

Is there any function/format to get it as Jan 16 2014?

推荐答案

使用.NET Stringbuilder-适用于全部您的格式需求-您将获得最大的收益:

By using a .NET Stringbuilder - for all your formatting needs - you get the most bang for the buck:

Option Explicit

Class cFormat
  Private m_oSB
  Private Sub Class_Initialize()
    Set m_oSB = CreateObject("System.Text.StringBuilder")
  End Sub ' Class_Initialize
  Public Function formatOne(sFmt, vElm)
    m_oSB.AppendFormat sFmt, vElm
    formatOne = m_oSB.ToString()
    m_oSB.Length = 0
  End Function ' formatOne
  Public Function formatArray(sFmt, aElms)
    m_oSB.AppendFormat_4 sFmt, (aElms)
    formatArray = m_oSB.ToString()
    m_oSB.Length = 0
  End Function ' formatArray
End Class ' cFormat

Dim oFmt : Set oFmt = New cFormat
WScript.Echo oFmt.FormatOne("Today: {0:MMM dd yyyy}", Date())
WScript.Echo oFmt.FormatOne("Today: {0:yyyy-MM-dd [MMMM]}", Date())

输出:

cscript 21279700.vbs
Today: Jan 22 2014
Today: 2014-01-22 [Januar]

此处查看背景。

这篇关于日期格式功能将日期显示为“ 2014年1月13日”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆