Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我用 python 为我的气象站做了一个小程序,它一切正常,但我有一个小问题。
输出显示为
2014/5/18 04:03:41 2014/5/18 19:47:41
我希望它显示为
04:03:41 19:47:41
有什么简单的方法可以做到这一点,我想把角色去掉,但这听起来比转换更像是一个障碍。
谢谢你的帮助
In [66]: t="2014/5/18 19:47:41".split() In [67]: print t[-1] 19:47:41
如果您有一个字符串,只需拆分并获取最后一个元素,即时间。
t="2014/5/18 04:03:41" from datetime import datetime str_time= datetime.strptime(t,'2014/5/18 %H:%M:%S').time() In [72]: print str_time 04:03:41
日期时间文档