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.
我有包含时间戳的字符串:
Wed Apr 24 14:39:49 CEST 2013
当然,我在许多记录中都有类似的值,所以我想在之前得到所有CEST。(我有记录和 CEST 2012、2013、2014 ......),以及 CEST 之后的一年。我也想删除日信息。
CEST
例如,我想要结果:
2013 Apr 24 14:39:49 2013 Apr 26 14:39:49
我应该使用什么方法?
谢谢
from dateutil import parser dt = parser.parse('Wed Apr 24 14:39:49 CEST 2013')
dt是一个日期时间对象,您可以使用/格式化任何您想要的方式。例如:
dt
dt.strftime('%Y %b %d %H:%M:%S') # returns '2013 Apr 24 14:39:49'