The following script will give local time with time zone information (TZ) in both true ISO8601 and human format (without 'T'). It converts the TZ offset in minutes to the required format HHMM, for example, 2019-01-25T08:26:55.347+1300and 2019-01-25 08:26:55.347+1300for NZ with DST.
@echo off
for /F "usebackq tokens=1,2 delims==" %%i in ('wmic os get LocalDateTime /VALUE 2^>NUL') do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ccyy_mm_dd=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%
set hh_mm_ss=%ldt:~8,2%:%ldt:~10,2%:%ldt:~12,2%
set _fff=%ldt:~14,4%
set tzsign=%ldt:~21,1%
set tzmins=%ldt:~22%
set /a tzHH=(%tzmins%/60)
set /a tzMM=(%tzmins%-(%tzHH%*60))
set /a tzHH=100 + %tzHH%
set tzHH=%tzHH:~1,2%
set /a tzMM=100 + %tzMM%
set tzMM=%tzMM:~1,2%
set ldt=%ccyy_mm_dd% %hh_mm_ss%%_fff%%tzsign%%tzHH%%tzMM%
set ldt8601=%ccyy_mm_dd%T%hh_mm_ss%%_fff%%tzsign%%tzHH%%tzMM%
echo %ldt%
echo %ldt8601%
You probably want to delete one of the echo commands
EDIT for those who wanted a colon in TZ, change %tzHH%%tzMM%to%tzHH%:%tzMM%
source
share