[removed] Return formatted date

前端 未结 3 1188
星月不相逢
星月不相逢 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:01

    The value returned by objFS.GetFile(strFile).DateLastModified is a date/time value. You can format this into a string using a formatting or conversion function:

    dateLastModified = objFS.GetFile(strFile).DateLastModified
    WScript.Echo FormatDateTime(dateLastModified, 2)
    

    This will format the date/time value into a short date. How this is done depends on your current regional settings. E.g. in some cultures you will have "MM/dd/yyyy" and in other cultures "dd-MM-yyyy" etc.

    You can also get complete control over the formatting by extracting the day, month and year part and putting them together into a string:

    dateLastModified = objFS.GetFile(strFile).DateLastModified
    WScript.Echo Day(dateLastModified) & "/" & Month(dateLastModified) & "/" & Year(dateLastModified)
    

提交回复
热议问题