Thread: Post #2

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    3
    Rep Power
    0

    Post #2


    How do I add the date to a program... I mean more like every time i run the program I want to print the date and current time... I have look at some tutorials on this subject and non of them seem to help.. ?? Can anyone help here?
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    The simplest way to do this is to use the strftime() function in the time module, which is included as part of the stdlib. For example...

    >>> from time import gmtime, strftime
    >>> strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
    'Thu, 28 Jun 2001 14:17:15 +0000'
    >>>
    You might also be intested in the datetime module (the second link below).

    http://www.python.org/doc/2.3.4/lib/module-time.html
    http://www.python.org/doc/2.3.4/lib/...-datetime.html

    Enjoy!

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Location
    Bimingham,AL
    Posts
    68
    Rep Power
    11
    t = time.localtime(time.time())
    st = time.strftime(" %d-%b-%Y %H:%M:%S", t)

IMN logo majestic logo threadwatch logo seochat tools logo