【问题标题】:discord.py current time commanddiscord.py 当前时间命令
【发布时间】:2021-05-04 15:34:22
【问题描述】:

我有这个时间命令,我想要它,这样当我说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

【问题讨论】:

    标签: discord discord.py


    【解决方案1】:

    您需要更改时区,可以使用名为 pytz 的库来完成

    $ pip install pytz
    

    代码:

    import pytz
    from datetime import datetime
    
    if message.content.startswith('p!time'):
        timestamp = datetime.now()
        pst = pytz.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)
    

    【讨论】:

      猜你喜欢
      • 2021-04-06
      • 2021-03-11
      • 2021-07-11
      • 1970-01-01
      • 2021-02-07
      • 2021-03-19
      • 2021-07-10
      • 1970-01-01
      • 2021-10-02
      相关资源
      最近更新 更多