Simple BAT and VBScript to simulate UNIX date /u. Nothing original, I
just stiched together some stuff from the groups. But have not seen
this particular solution before.
========================================================================
== NowUTC.vbs
========================================================================
Option Explicit
Dim UTC
Dim LocalTZ
Dim TZOffset
For Each LocalTZ in
GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")
TZOffset = LocalTZ.CurrentTimeZone
Next
if TZOffset < 0 Then
UTC = DateAdd("n", ABS(TZOffset), CDate(Now))
else
UTC = DateAdd("n", -ABS(TZOffset), CDate(Now))
end if
Wscript.Echo FmtLZ(Year(UTC), 4) & FmtLZ(Month(UTC), 2) &
FmtLZ(Day(UTC), 2) & FmtLZ(Hour(UTC), 2) & FmtLZ(Minute(UTC), 2) &
FmtLZ(Second(UTC), 2)
Function FmtLZ(NValue, NLength)
FmtLZ = String(NLength - Len(CStr(NValue)), "0") & CStr(NValue)
End Function
=====================================================================
== Test.bat
=====================================================================
@ECHO OFF
:: ------------------------------------------------------------------
:: Run the VBScript and capture its output as the environment
:: variable NowUTC, in the format YYYYMMDDHHNNSS
:: ------------------------------------------------------------------
FOR /F "tokens=*" %%A in ('cscript NowUTC.vbs //nologo') DO SET
NowUTC=%%A
:: ------------------------------------------------------------------
:: As a demo, show NowUTC and how to breakout the parts
:: ------------------------------------------------------------------
ECHO NowUTC env variable is "%NowUTC%"
ECHO The parts of NowUTC are:
ECHO Year = %NowUTC:~0,4%
ECHO Month = %NowUTC:~4,2%
ECHO Day = %NowUTC:~6,2%
ECHO Hour = %NowUTC:~8,2%
ECHO Minute = %NowUTC:~10,2%
ECHO Second = %NowUTC:~12,2%