Skip to content

Instantly share code, notes, and snippets.

@1ijack
Last active January 23, 2019 05:31
Show Gist options
  • Save 1ijack/e095d3b15e133b50db692a857d92961b to your computer and use it in GitHub Desktop.
Save 1ijack/e095d3b15e133b50db692a857d92961b to your computer and use it in GitHub Desktop.
Query wmic for OS Localtime
:: by JaCk | Release 01/22/2019 | https://gist.github.com/1ijack/e095d3b15e133b50db692a857d92961b | wmic_localTime.cmd -- Query wmic for OS Localtime
:: based on https://ss64.com/nt/syntax-gmt.html
@call :func_wmic_localTime bam
@if defined bam @echo/%bam%
@set "bam="
@exit /b
:func_wmic_localTime
@set "#tA=%~1"
@if not defined #tA (@goto:eof) else @set "#tA="
@for /f "tokens=1,2 delims==" %%G in ('wmic path Win32_LocalTime get /value') do @call set "l%%G=0000%%H"
@set /a "lSecond=(1%lSecond:~-2%-100)+((1%lMinute:~-2% - 100)*60) + (%lHour:~-2%*3600)"
@set "%~1=%lYear:~-4%.%lMonth:~-2%.%lDay:~-2%.%lSecond%"
@for %%# in (l,lDay,lDayOfWeek,lHour,lMilliseconds,lMinute,lMonth,lQuarter,lSecond,lWeekInMonth,lYear) do @set "%%#="
@if not defined %~1 @exit /b 1
@goto:eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment