Tom Del Rosso
2020-12-06 01:50:10 UTC
The last line is the thing I want to point out. It's a single equation
that converts the hour from 24-hour format to 12-hour format. I'm sure
this would run faster than an IF statement and more so if the IF was
followed by a GOTO. In the past I have used IF because I hadn't thought
of doing it all in arithmetic. But I don't see a way to avoid the IF
that chooses am and pm.
set tm=%time%
set hr=%tm:~0,2%
if %hr% LSS 12 (set AMPM=am) else (set AMPM=pm)
set /a hr=hr%%12 + !hr*12 + !(hr-12)*12
--
that converts the hour from 24-hour format to 12-hour format. I'm sure
this would run faster than an IF statement and more so if the IF was
followed by a GOTO. In the past I have used IF because I hadn't thought
of doing it all in arithmetic. But I don't see a way to avoid the IF
that chooses am and pm.
set tm=%time%
set hr=%tm:~0,2%
if %hr% LSS 12 (set AMPM=am) else (set AMPM=pm)
set /a hr=hr%%12 + !hr*12 + !(hr-12)*12
--