Datetime module

Discussion in 'Python' started by rublind@gmail.com, Jan 10, 2005.

  1. Guest

    I am writing a script that acts as an AIM bot [using twisted.IM's base
    scripts] and I want to add a logging feature. I got it to log who sends
    what to whom, but what I want to add is the date and time that the
    message was sent (or recieved by the bot), I tried to look at datetime
    on my own, and I couldn't get anything to work.
    Anyone know a simple way to get the current date and/or time?

    Thanks!
    , Jan 10, 2005
    #1
    1. Advertising

  2. Binu K S Guest

    The time module will do.
    >>> import time
    >>> time.ctime()

    'Mon Jan 10 11:17:54 2005'

    Use strftime if you need to format the time differently.
    >>> time.strftime("%Y-%m-%d %H:%m:%S",time.localtime())

    '2005-01-10 11:01:45'

    On 9 Jan 2005 21:46:12 -0800, <> wrote:
    > I am writing a script that acts as an AIM bot [using twisted.IM's base
    > scripts] and I want to add a logging feature. I got it to log who sends
    > what to whom, but what I want to add is the date and time that the
    > message was sent (or recieved by the bot), I tried to look at datetime
    > on my own, and I couldn't get anything to work.
    > Anyone know a simple way to get the current date and/or time?
    >
    > Thanks!
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Binu K S, Jan 10, 2005
    #2
    1. Advertising

  3. Guest

    take a look at the logging module as well, in the documentation
    (paragraph 6.29.2 for release 2.4) you find a basic example
    , Jan 10, 2005
    #3
  4. wrote:

    >I am writing a script that acts as an AIM bot [using twisted.IM's base
    >scripts] and I want to add a logging feature. I got it to log who sends
    >what to whom, but what I want to add is the date and time that the
    >message was sent (or recieved by the bot), I tried to look at datetime
    >on my own, and I couldn't get anything to work.
    >Anyone know a simple way to get the current date and/or time?
    >
    >>> import datetime
    >>> datetime.datetime.now()

    datetime.datetime(2005, 1, 10, 6, 39, 56, 64000)
    >>> print datetime.datetime.now()

    2005-01-10 06:40:03.705000
    >>>


    You may also want to consider using the logging module.

    // m
    Mark McEahern, Jan 10, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    704
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    532
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    386
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    333
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    754
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page