Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Convert a Date Time to just Time

I have a field that shows time as 1900-01-01 00:05:00 but I want to show it as just 00:05:00 i.e. just five minutes.

I have been looking at the python documentation and it is driving me crazy. From the question How do I find the time difference between two datetime objects in python? it looks like is should be something do with timedelta but I am not getting any closer to a solution. The question Converting Date/Time to Just Time suggests you can just use a format tag but that is not working for me. I also looked at converting date time to string without success, I know this is something simple but I have looked at hundreds of pages looking for something simple. All help would be appreciated.

like image 221
Brett Avatar asked Mar 29 '15 02:03

Brett


1 Answers

Say you have a Datetime object now:

now.time().strftime('%H:%M:%S')

like image 74
satoru Avatar answered Sep 22 '22 05:09

satoru