[Tutor] how to extract time from datetime.date.time()

Jason Massey jason.massey at gmail.com
Thu Nov 16 18:39:57 CET 2006


How about two different ways:

>>> import datetime
>>> t = datetime.datetime.now()
>>> t
datetime.datetime(2006, 11, 16, 11, 28, 15, 750000)
>>> t.hour
11
>>> t.minute
28
>>> t.second
15
>>> a = "%d:%d:%d" % (t.hour,t.minute,t.second)
>>> a
'11:28:15'
>>>

or, a bit more succinctly:

>>> t.strftime('%H:%M:%S')
'11:28:15'

All of this info is readily avaliable in the python docs.

http://docs.python.org/lib/module-datetime.html


On 11/16/06, Asrarahmed Kadri <ajkadri at googlemail.com> wrote:
>
> Hi,
>
> I want to extract hh:mm:ss from below mentioned code:
>
> import datetime
> >>> t = datetime.datetime.now()
> >>> print t
> 2006-11-16 16:59:02.843000
>
> How to do it?
>
> TIA.
> Regards,
> Asrarahmed
>
> --
> To HIM you shall return.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061116/4b67b8b0/attachment.htm 


More information about the Tutor mailing list