这是我自己的尝试。更好的解决方案将受到大家的认可!
Function ToDateTimeStringMinimalSeparators(dateTime)
' --------------------------------------------------------------------------
' F O R M A T T H E U T C O F F S E T
' --------------------------------------------------------------------------
Dim oShell, activeTimeBias
Set oShell = CreateObject("WScript.Shell")
activeTimeBias = oShell.RegRead("HKEY_LOCAL_MACHINE\System\" & _
"CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")
Dim sign
sign = "-"
If activeTimeBias < 0 Then
sign = "+"
' Make it positive while we're doing calculations
activeTimeBias = activeTimeBias * -1
End If
Dim atbHours, atbMins
atbHours = Right("00" & Int(activeTimeBias/60), 2)
atbMins = Right("00" & (activeTimeBias Mod 60), 2)
If atbMins = "00" Then
atbMins = ""
End If
Dim utcOffset
utcOffset = sign & atbHours & atbMins
' --------------------------------------------------------------------------
' F O R M A T T H E M A I N D A T E
' --------------------------------------------------------------------------
Dim dateBody
dateBody = Right("0000" & Year(dateTime), 4) & _
Right("00" & Month(dateTime), 2) & _
Right("00" & Day(dateTime), 2) & _
"T" & _
Right("00" & Hour(dateTime), 2) & _
Right("00" & Minute(dateTime), 2) & _
Right("00" & Second(dateTime), 2)
ToDateTimeStringMinimalSeparators = dateBody & utcOffset
End Function
+1绝对有资格成为更好的解决方案!我不知道你可以从VBScript实例化.NET对象。 – 2010-08-07 12:30:50
@DamianPowell只有一些COM暴露类的列表可以在注册表'HKEY_CLASSES \ System.'键*(即'System.Text.StringBuilder')*中找到,只需查看列表即可查看暴露的内容。 – Lankymart 2016-06-02 13:38:55