VBS 不正确的日期时间格式 [英] VBS incorrect datetime format

查看:47
本文介绍了VBS 不正确的日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将 dateTimne 写入文件的 VBScript.

I have a VBScript that writes a dateTimne to a file.

Option Explicit  
Dim fso, path, file, recentDate, recentFile, objFileHandle
Set fso = CreateObject("Scripting.FileSystemObject")
Set recentFile = Nothing
For Each file in fso.GetFolder("\\path\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("\\path\folder\DateTime.Txt", 2, "True")
objFileHandle.Write(FormatDateTime(recentFile.DateLastModified) )
objFileHandle.Close

当我在我的服务器上手动运行它时,它给了我一个美国格式的 mm/dd/yyyy hh:mm:ss AM,例如 11/14/2013 9:20:56 AM.

When i run it manually on my server it gives me a US format of mm/dd/yyyy hh:mm:ss AM eg 11/14/2013 9:20:56 AM.

当我在笔记本电脑上运行它时,它会返回我真正想要的英国格式 - dd/mm/yyyy hh:mm:ss AM,例如 14/11/2013 9:20:56 AM.

When i run it on my Laptop it gives me back the UK format i actually want - dd/mm/yyyy hh:mm:ss AM eg 14/11/2013 9:20:56 AM.

有什么想法吗?

推荐答案

试试这个:

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

' YYYY-MM-DD HH:MM:SS (24h ISO 8601 Format)
' You can permutate parameters and delemiters the way you want.

Dim thisday , thistime
thisday = Date
thistime = Time

Set objFileHandle = fso.OpenTextFile("folder\DateTime.Txt", 2, "True")
objFileHandle.Write(Year(thisday) & "-" & Month(thisday) & "-" & Day(thisday) &" "&  Hour(thistime) & ":" & Minute(thistime) & ":" & Second(thistime) )
objFileHandle.Close

如果您不使用 ISO 8601 标准,请将其复制并粘贴到您的 .VBS 文件中并调整您想要的内容

Copy this and past it into your .VBS File and adjust what you want if you are not working with ISO 8601 Standard

这篇关于VBS 不正确的日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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