::::::::::::::::::::::::::::::::
:: Parse Date/Time
::
:: Test/Example:
::
:: ParseDateTime.cmd WITHECHO
:: echo date=[%date%] time=[%time%] year=[%year%] month=[%month%] day=[%day%] hour=[%hour%] minute=[%minute%] second=[%second%] hundredth=[%hundredth%]
::
::::::::::::::::::::::::::::::::
@echo off&setlocal
for /f "tokens=1-4 delims=/-. " %%G in ('date /t') do (call :s_fixdate %%G %%H %%I %%J)
goto :s_print_the_date
:s_fixdate
if "%1:~0,1%" gtr "9" shift
for /f "skip=1 tokens=2-4 delims=(-)" %%G in ('echo.^|date') do (set %%G=%1&set %%H=%2&set %%I=%3)
goto :eof
:s_print_the_date
endlocal&(
echo.|date|find "JJ">nul
if errorlevel 1 (
:: English locale
REM echo year:[%yy%] month:[%mm%] day:[%dd%]
set year=%yy%
set month=%mm%
set day=%dd%
) else (
:: German locale
REM echo jahr:[%JJ%] monat:[%MM%] tag:[%TT%]
set year=%JJ%
set month=%MM%
set day=%TT%
)
)
for /f "tokens=1-4 delims=.:, " %%i in ("%time%") do (
set hour=%%i
set minute=%%j
set second=%%k
set hundredth=%%l
)
if %hour% lss 10 set hour=0%hour%
if "%1"=="WITHECHO" echo %year%-%month%-%day% %hour%:%minute%:%second%.%hundredth%