Skip to content

Instantly share code, notes, and snippets.

@tinytengu
Last active September 23, 2021 17:05
Show Gist options
  • Save tinytengu/55a9aa32c301632f575491515cbbb88b to your computer and use it in GitHub Desktop.
Save tinytengu/55a9aa32c301632f575491515cbbb88b to your computer and use it in GitHub Desktop.
Fix %time% output (add leading 0, trim ms)
:time_fix
set _time=%~1
if "%_time:~0,1%"==" " set %~2=0%_time:~1%
if "%_time:~1,1%"==":" set %~2=0%_time%
if "%~3"=="1" set %~2=0%_time:~0,7%
exit /B 0
rem Usage: CALL :time_fix %time% time_fixed
rem echo %time_fixed%
rem Usage with trimming: CALL :time_fix %time% time_fixed 1
rem echo %time_fixed%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment