Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Datetime module

Reply
Thread Tools

Datetime module

 
 
rublind@gmail.com
Guest
Posts: n/a
 
      01-10-2005
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!

 
Reply With Quote
 
 
 
 
Binu K S
Guest
Posts: n/a
 
      01-10-2005
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
>

 
Reply With Quote
 
 
 
 
wittempj@hotmail.com
Guest
Posts: n/a
 
      01-10-2005
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

 
Reply With Quote
 
Mark McEahern
Guest
Posts: n/a
 
      01-10-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [2.4.4] creating a datetime.datetime from an XML xs:dateTime skip@pobox.com Python 2 01-06-2009 01:31 PM
[2.4.4] creating a datetime.datetime from an XML xs:dateTime Martin Python 0 12-27-2008 08:08 PM
mx.DateTime to datetime.datetime mp Python 1 07-28-2006 10:57 PM
datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Christos TZOTZIOY Georgiou Python 3 09-13-2003 10:44 AM
RE: datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Tim Peters Python 0 09-09-2003 12:57 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57