Converting Python time to another format
2 answers
If your time string is of a fixed width, you can simply get the substring from the original time string:
In [90]: ts = '2014-12-17 08:00:00.23'
In [91]: ts[-11:-3]
Out[91]: '08:00:00'
If you want to get a datetime object, use datetime
either instead dateutil
:
In [99]: from dateutil import parser
...: dt = parser.parse(ts)
...: dt.strftime("%H:%M:%S")
Out[99]: '08:00:00'
0
source to share