This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

12 hr > 24 hr clock

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
NewzNZ
Halfop
Posts: 68
Joined: Thu Mar 05, 2009 5:15 am
Contact:

12 hr > 24 hr clock

Post by NewzNZ »

Hi all

I have a weather script that pulls data from a site to post.
It displays the time in 12 format - just wondering if there's a way to convert that to display in 24 hour format?

eg 2:35pm becomes 14:35

Thanks in advance!
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Try this maybe...

Code: Select all

set time24 [clock format [clock scan "2:35 pm" -format "%I:%M %p"] -format "%H:%M"]
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
NewzNZ
Halfop
Posts: 68
Joined: Thu Mar 05, 2009 5:15 am
Contact:

Post by NewzNZ »

Great - thanks for the reply SpiKe^^.

Do you know if there's a way with that code to turn any 12hr time format into 24hr? Maybe with wildcards?

Cheers again.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Lol, That time string "2:35 pm" could be the variable holding that time value you need converted:)

Code: Select all

set sometime "2:35 pm"
set time24 [clock format [clock scan $sometime -format "%I:%M %p"] -format "%H:%M"]
The exact way you might fit that into someone's script would be a little different for every script.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
NewzNZ
Halfop
Posts: 68
Joined: Thu Mar 05, 2009 5:15 am
Contact:

Post by NewzNZ »

Thanks! Will give that a go! =)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Goodluck.

If ya need more help, post the weather script here.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
NewzNZ
Halfop
Posts: 68
Joined: Thu Mar 05, 2009 5:15 am
Contact:

Post by NewzNZ »

Will do! Thanks =)
Post Reply