python - 怎么添加: to a time formatted like this 203045 in python?

标签 python formatting timestamp

我一直在尝试在 python 中获取从 203045 到 20:40:45 的时间格式化值。我显然不知道从哪里开始。任何帮助将不胜感激! 谢谢!

最佳答案

使用datetime中的strptimestrftime函数,前者从字符串构造日期时间对象,后者将日期时间对象格式化为特定的字符串格式:

from datetime import datetime
datetime.strptime("203045", "%H%M%S").strftime("%H:%M:%S")
# '20:30:45'

关于python - 怎么添加: to a time formatted like this 203045 in python?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38424793/

相关文章:

python - 动态添加域到 scrapycrawlspiderdeny_domains 列表

python - 类型错误 : unsupported operand type(s) for -: 'str' and 'str' in python 3. x python

c++ - 仅使用标准 C++ 将任何 float 打印到恰好 N 个空格

mysql - 日期插入mysql表

java - 如何将java时间戳转换为php时间戳?

java - JestResult.getSourceAsObjectList - 适用于 "@timestamp"或看似以 "@"开头的任何字段

python - Keras model.predict 始终为 0

ruby-on-rails - Ruby Rubocop - 更喜欢使用 MatchData

html - Excel 不应用 HTML 中的 mso 数字格式

python - 在文本文件中匹配 id 并检索相应值的更快方法