Convert local time into 24hr

Hewlett-packard / Sd2100
July 6, 2009 at 17:17:52
Specs: Windows Vista, 1024

how would i use a batch to convert a variable into 24hour time?


set /p time=Enter local time:

then take that variable and calculate the local time into 24 format.

i tried googling and searched on here but nothing.

thanks the help.

See More: Convert local time into 24hr

Report •

July 7, 2009 at 02:28:13
Is this homework.
It depends on what format you enter the time.

ie 12:34pm 12.34am ect.

Report •

July 7, 2009 at 03:51:29
no its not homework. i would like it in

such as 1:00 pm = 1300 etc.

i dont really understand your Question tho.


Report •

July 7, 2009 at 05:55:46
I suggest you use a language with date logic. Like VBScript.
WScript.Echo FormatDateTime(Now, 4)

Report •

Related Solutions

July 7, 2009 at 12:54:43
Hi Brockey


Try this,
What I meant by the formats is a user could enter
01:30 am
1:30 am
Below it'nt perfect but it caters for the above formats
I've used XTime because it's not good to reset the system variable %Date%

@echo off
SetLocal EnableDelayedExpansion
set /p XTime=Enter local time:
for /f "tokens=1-2 delims=:" %%a in ("%XTime%") do (
set Hr=%%a
set Min=%%b
set Suffix=!Min:~-2!
set Min=!Min:~,2!
if "!Hr:~0,1!"=="0" (set Hr=!Hr:~1,1!)
if "!Hr!"=="12" (if "!Suffix!"=="am" (set Hr=0))
if "!Suffix!"=="pm" (if !Hr! LSS 12 (set /a Hr+=12))
if !Hr! LSS 10 (set Hr=0!Hr!)
echo !Hr!:!Min!

Report •

July 7, 2009 at 16:06:46
Thank you that worked out great.

Report •

Ask Question