On Thu, 2006-11-16 at 17:28 +0000, Asrarahmed Kadri 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?

The python interpreter can be pretty helpful for this kind of question.

>>> import datetime
>>> t = datetime.datetime.now()
>>> t
datetime.datetime(2006, 11, 16, 12, 44, 23, 766220)
>>> dir(t)
['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__ge__', 
'__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', 
'__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', 
'__rsub__', '__setattr__', '__str__', '__sub__', 'astimezone', 'combine', 
'ctime', 'date', 'day', 'dst', 'fromordinal', 'fromtimestamp', 'hour', 
'isocalendar', 'isoformat', 'isoweekday', 'max', 'microsecond', 'min', 
'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime', 
'time', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 
'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple', 'weekday', 'year']
>>> t.hour
12
>>> t.min
datetime.datetime(1, 1, 1, 0, 0)
>>> t.minute
44
>>> t.second
23

The dir function returns the contents of an object.

min and minute were the likely names for the the number of minutes.

Your Python installation should have included the documentation, but you
can also go to the python.org web site.  The module index provides links
to each module's documentation.

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

Reading the module documentation we find that min is the minimum
datetime value and has nothing to do with minutes.

>  
> TIA.
> Regards,
> Asrarahmed
> 
> -- 
> To HIM you shall return. 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
-- 
Lloyd Kvam
Venix Corp

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to