【发布时间】:2018-07-10 18:27:53
【问题描述】:
我目前有一个程序可以跟踪一个人何时登录,以及他们何时因不和谐而退出。该程序以日期时间对象的形式给出了签署时间和签署时间,并将它们彼此相减,得到总数。问题是我希望它只给我小时和分钟,而不是秒和毫秒。 代码如下:
@bot.event
async def on_message(message):
if "on" in message.content:
player = message.author
time = message.timestamp
message_type = 'on'
with open(str(player) + " on", 'w') as f:
f.seek(0)
f.truncate()
f.write(str(time))
elif "off" in message.content:
player = message.author
off_time = message.timestamp
with open(str(player) + " on",'r+') as f:
on_time = f.readline()
f.seek(0)
f.truncate()
on_time = parser.parse(on_time)
total = off_time - on_time
print(total)
注意:total对象是timedelta对象,不是timedate对象。
【问题讨论】:
-
不幸的是,虽然第一个 dup 有你想要的答案,但它不是那里接受的答案。所以你必须去the second answer。
标签: python python-3.x