Military Time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wocosc
    New Member
    • Mar 2007
    • 18

    Military Time

    I have a quick question.. How can get python to take whatever time of day it is, and output it as military time? I already know how to get it to return the specific time.
  • wocosc
    New Member
    • Mar 2007
    • 18

    #2
    I would like to store the current time and then convert it to military time and then print it on screen. Any help would be great..

    Comment

    • dshimer
      Recognized Expert New Member
      • Dec 2006
      • 136

      #3
      I would use time.localtime( ) see docs and build whatever format I wanted out of the returned list.
      Code:
      >>> import time
      >>> time.localtime()
      (2007, 4, 25, 11, 56, 26, 2, 115, 1)

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by wocosc
        I would like to store the current time and then convert it to military time and then print it on screen. Any help would be great..
        Once you have a time object, as in:
        Code:
        theTime = time.localtime()
        use strftime() to format the output. strftime() takes a fomat string like "%H:%m:%s" to make the format what ever you specify:I'd like to be of more help, but I'm at a compter that doesn't have Python installed on it.

        Welcome to the Python Forum on TheScripts.com.

        Comment

        Working...