我有这个时间命令,我想要它,当我说 p!time
时,它会说 PST time:, EST time:, etc
if message.content.startswith('p!time'):
timestamp = datetime.now()
await message.channel.send(timestamp)
await message.channel.send(timestamp.strftime(r"%I:%M %p"))
#now idk what to do
答案 0 :(得分:2)
您需要更改时区,可以使用名为 pytz
# pip install pytz
import pytz
from datetime import datetime
if message.content.startswith('p!time'):
timestamp = datetime.now()
pst = timezone('US/Pacific')
est = pytz.timezone('US/Eastern')
msg = f"PST Time: {timestamp.astimezone(pst).strftime("%I:%M %p")}, EST Time: {timestamp.astimezone(est).strftime("%I:%M %p")}"
await message.channel.send(msg)