Created
July 2, 2016 19:35
-
-
Save nerflad/df681322354b75bdd5e235c4f1fdfb5d to your computer and use it in GitHub Desktop.
Windows: Get fancy formatted time from WMIC if you don't have access to Command Extensions (for native %date% and %time%)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: This is not mine! | |
:: This is almost verbatim from an answer on stack exchange! | |
@echo off | |
setlocal EnableDelayedExpansion | |
setlocal | |
:getTime | |
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do ( | |
set "dt=%%a" | |
set "YYYY=!dt:~0,4!" | |
set "MM=!dt:~4,2!" | |
set "DD=!dt:~6,2!" | |
set "HH=!dt:~8,2!" | |
set "Min=!dt:~10,2!" | |
set "Sec=!dt:~12,2!" | |
set "date=!MM!-!DD!-!YYYY!" | |
set "time=!HH!:!Min!:!Sec!" | |
) | |
goto :EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment