[removed] Return formatted date

前端 未结 3 1200
星月不相逢
星月不相逢 2020-12-07 05:35

I am executing a VBS file that returns the modified date of another file:

Set objFS=CreateObject(\"Scripting.FileSystemObject\")
Set objArgs = WScript.Argume         


        
3条回答
  •  醉梦人生
    2020-12-07 06:00

    As demonstrated here and https://stackoverflow.com/a/21280396/603855, vou can use a .Net StringBuilder to solve all your formatting problem without depending on locales or doing extra/specific work:

    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:dd\/MM\/yyyy}", Date())
    

    output:

    Today: 08/02/2014
    

提交回复
热议问题