Created
October 19, 2017 12:47
-
-
Save TheDcoder/0b9aee922ff4cb61056d9a11c6812a5b to your computer and use it in GitHub Desktop.
Locale-indepent way to get time and date in batch
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
@echo off | |
rem I do not claim authorship of this snippet, original source: https://serverfault.com/a/227375/414453 | |
rem Get the time from WMI - at least that's a format we can work with | |
set X= | |
for /f "skip=1 delims=" %%x in ('wmic os get localdatetime') do if not defined X set X=%%x | |
echo.%X% | |
rem dissect into parts | |
set DATE.YEAR=%X:~0,4% | |
set DATE.MONTH=%X:~4,2% | |
set DATE.DAY=%X:~6,2% | |
set DATE.HOUR=%X:~8,2% | |
set DATE.MINUTE=%X:~10,2% | |
set DATE.SECOND=%X:~12,2% | |
set DATE.FRACTIONS=%X:~15,6% | |
set DATE.OFFSET=%X:~21,4% | |
echo %DATE.YEAR%-%DATE.MONTH%-%DATE.DAY% %DATE.HOUR%:%DATE.MINUTE%:%DATE.SECOND%.%DATE.FRACTIONS% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment