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

Mike Hansen Mike.Hansen at atmel.com
Thu Nov 16 18:38:21 CET 2006


 

> -----Original Message-----
> From: tutor-bounces at python.org 
> [mailto:tutor-bounces at python.org] On Behalf Of Asrarahmed Kadri
> Sent: Thursday, November 16, 2006 10:29 AM
> To: tutor-python
> Subject: [Tutor] how to extract time from datetime.date.time()
> 
> 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. 
>

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

I believe datetime.datetime.now() returns a datetime object. You can
just look at the attributes of the object.

In [6]: import datetime

In [7]: t = datetime.datetime.now()

In [8]: t.hour
Out[8]: 10

In [10]: t.minute
Out[10]: 33

In [11]: t.second
Out[11]: 37
-------------- next part --------------
-------------

  NOTICE:  This e-mail transmission and any documents or files attached to
  it contain information for the sole use of the above-identified individual or entity.

  Its contents may be privileged, confidential, and exempt from disclosure under the law.
  Any dissemination, distribution, or copying of this communication is strictly prohibited.

  Please notify the sender immediately if you are not the intended recipient.

FGNS


More information about the Tutor mailing list