0

我有一个脚本,它读取远程目录中的所有文件并将文件对象设置为最旧的文件。然后它将该文件的创建/修改日期写入另一个文件。

问题:它以一种奇怪的格式写入日期 - yyyy-dd-mm hh:mm:ss 我想要格式 yyyy-mm-dd hh:mm:ss

Option Explicit  
Dim fso, path, file, recentDate, recentFile, objFileHandle
Set fso = CreateObject("Scripting.FileSystemObject")
Set recentFile = Nothing
For Each file in fso.GetFolder("\\remoteServer\Drive\Folder").Files
  If (recentFile is Nothing) Then
    Set recentFile = file
  ElseIf (file.DateLastModified < recentFile.DateLastModified) Then
    Set recentFile = file
  End If
Next

Set objFileHandle = fso.OpenTextFile("\\remoteServer\Drive\Folder\oldestDateTime.Txt", 2, "True")
objFileHandle.Write(recentFile.DateLastModified)
objFileHandle.Close

有人知道如何获得我想要的格式吗?

4

1 回答 1

-1

根据这个网站

objFileHandle.Write(FormatDateTime(recentFile.DateLastModified, vbShortDate))

应该以某种方式给你你想要的东西。

当然,除非您在谈论基于区域设置的格式?另请参阅此问题:VBS objFile.DateLastModified and Date Format Settings and its answers

于 2013-11-12T12:40:17.213 回答