以前は、UTCタイムフォーマットから”YYYYMMDDHHMMSS”に変換するスクリプトでした。

今度は、逆です。YYYYMMDDやHHMMSSを取得するスクリプトの使用しています。

Option Explicit
  Dim STR_Computer
  Dim OBJ_SWbemServices
  Dim OBJ_TimeZone
  Dim COL_TimeZone
  Dim STR_Bias
  Dim DTMCurrentDate
  Dim DTMTargetDate
  Dim DTMMonth
  Dim DTMDay

  STR_Computer = "."
  Set OBJ_SWbemServices = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & STR_Computer & "\root\cimv2")
  Set COL_TimeZone = OBJ_SWbemServices.ExecQuery("SELECT * FROM Win32_TimeZone")

  For Each OBJ_TimeZone In COL_TimeZone

    STR_Bias = OBJ_TimeZone.Bias

  Next

  DTMTargetDate = Get_YYYYMMDD(0) & Get_HHMMSS(0)
  DTMTargetDate = DTMTargetDate & ".000000"
  DTMTargetDate = DTMTargetDate & CStr(STR_Bias)

  WScript.Echo DTMTargetDate
Private Function Get_YYYYMMDD(ByVal STR_Flag)
  Dim STR_Temp
  Dim STR_YYYYMMDD

  If Not IsNumeric(STR_Flag) Then Exit Function End If

  STR_Temp = Year(Now)
  If Len(STR_Temp) = 2 Then STR_Temp = "20" & STR_Temp End If
  If STR_Flag >= 1 Then STR_Temp = STR_Temp & "/" End If
  STR_YYYYMMDD = STR_Temp

  STR_Temp = Month(Now())
  If Len(STR_Temp) = 1 Then STR_Temp = "0" & STR_Temp End If
  If STR_Flag >= 1 Then STR_Temp = STR_Temp & "/" End If
  STR_YYYYMMDD = STR_YYYYMMDD & STR_Temp

  STR_Temp = Day(Now())
  If Len(STR_Temp) = 1 Then STR_Temp = "0" & STR_Temp End If
  STR_YYYYMMDD = STR_YYYYMMDD & STR_Temp

  GET_YYYYMMDD = STR_YYYYMMDD
End Function

 
Private Function GET_HHMMSS(ByVal STR_Flag)
  Dim STR_Temp
  Dim STR_HHMMSS

  If Not IsNumeric(STR_Flag) Then Exit Function End If

  STR_Temp = Hour(Now())
  If Len(Hour(Now())) = 1 Then STR_Temp = "0" & Hour(Now())
  If STR_Flag >= 1 Then STR_Temp = STR_Temp & ":" End If
  STR_HHMMSS = STR_Temp

  STR_Temp = Minute(Now())
  If Len(Minute(Now())) = 1 Then STR_Temp = "0" & Minute(Now())
  If STR_Flag >= 1 Then STR_Temp = STR_Temp & ":" End If
  STR_HHMMSS = STR_HHMMSS & STR_Temp

  STR_Temp = Second(Now())
  If Len(Second(Now())) = 1 Then STR_Temp = "0" & Second(Now())
  STR_HHMMSS = STR_HHMMSS & STR_Temp

  GET_HHMMSS = STR_HHMMSS
End Function

Scriptのダウンロードは こちら です。