Computing.Net > Forums > Programming > Convert local time into 24hr

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Convert local time into 24hr

Reply to Message Icon

Name: brockey01
Date: July 6, 2009 at 17:17:52 Pacific
OS: Windows Vista
CPU/Ram: 1024
Product: Hewlett-packard / Sd2100
Subcategory: Batch
Comment:

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

like

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.
Brock



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: July 7, 2009 at 02:28:13 Pacific
Reply:

Hi
Is this homework.
It depends on what format you enter the time.

ie 12:34pm 12.34am ect.


0

Response Number 2
Name: brockey01
Date: July 7, 2009 at 03:51:29 Pacific
Reply:

no its not homework. i would like it in

such as 1:00 pm = 1300 etc.

i dont really understand your Question tho.

thanks


0

Response Number 3
Name: Razor2.3
Date: July 7, 2009 at 05:55:46 Pacific
Reply:

I suggest you use a language with date logic. Like VBScript.

WScript.Echo FormatDateTime(Now, 4)


0

Response Number 4
Name: dtech10
Date: July 7, 2009 at 12:54:43 Pacific
Reply:

Hi Brockey

Hi

Try this,
What I meant by the formats is a user could enter
01:30am
01:30 am
1:30am
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!
)


0

Response Number 5
Name: brockey01
Date: July 7, 2009 at 16:06:46 Pacific
Reply:

Thank you that worked out great.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Convert local time into 24hr

VB6 Convert local time to utc www.computing.net/answers/programming/vb6-convert-local-time-to-utc/9124.html

Convert an editbox into textfile www.computing.net/answers/programming/convert-an-editbox-into-textfile-/5240.html

Save the time into a .ini file using .vbs www.computing.net/answers/programming/save-the-time-into-a-ini-file-using-vbs/19391.html