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.
我从第三方服务字符串中获取时间。它看起来像PT8H30M。什么是时间格式以及它如何datetime在 Python 2.7 中转换为对象
PT8H30M
datetime
如果我们假设格式只给出小时和分钟,您可以使用它datetime.datetime.strptime()来解析它们,并datetime.time从结果中返回一个对象:
datetime.datetime.strptime()
datetime.time
>>> from datetime import datetime >>> datetime.strptime('PT8H30M', 'PT%HH%MM').time() datetime.time(8, 30)