【发布时间】:2019-05-25 04:46:16
【问题描述】:
我有一个想要在网站上显示的 python 日期时间对象,但是时间以 hh:mm:ss 格式显示,我想以 hh:mm 格式显示它。
我已尝试使用以下替换方法:
message.timestamp.replace(second='0', microsecond=0)
但是这并没有变红,它只是用 hh:mm:00 替换它
【问题讨论】:
标签: python
我有一个想要在网站上显示的 python 日期时间对象,但是时间以 hh:mm:ss 格式显示,我想以 hh:mm 格式显示它。
我已尝试使用以下替换方法:
message.timestamp.replace(second='0', microsecond=0)
但是这并没有变红,它只是用 hh:mm:00 替换它
【问题讨论】:
标签: python
使用strftime()函数
>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2018, 12, 27, 11, 14, 37, 137010)
>>> now = datetime.now()
>>> now.strftime("%H:%M")
'11:15'
【讨论】: