我如何获得第一个时间和最后一个日期,但还包括时区?

How would i get the time to be first and the date last but also include the timezone?

你好,我正在尝试让我的机器人使用 discord.py 来发出早上好命令并说出日期和时间,但日期在前,时间在后,但还有军事时间和年份第一次约会我该如何解决这个问题? Response from bot

@client.command(aliases=["gm"])
async def goodmorning(ctx):
    embed = discord.Embed(description= f"Good Morning, it is currently {ctx.message.created_at}", colour = 0x8bc1a9)
    
    discord.Embed.timestamp = ctx.message.created_at

    await ctx.send(embed = embed)

Message.created_at 是一个 datetime.datetime 对象,因此您可以使用 datetime.datetime.strftime,它将日期时间格式化为您传递的格式的字符串。您可以找到格式代码 here.

因此,例如,如果我想要 MM/DD/YYYY HH:MM AM/PM 格式的日期时间,我会使用:

formatted_datetime = ctx.message.created_at.strftime("%m/%d/%Y %I:%M %p")
embed = discord.Embed(description=f"Good Morning, it is currently {formatted_datetime}", colour=0x8bc1a9)
embed.timestamp = ctx.message.created_at
await ctx.send(embed=embed)

作为旁注,discord.Embed 是对 Embed class 的引用,而不是您的 Embed 对象。因此,要为您的对象设置时间戳,您需要像我在上面的示例中那样使用 embed.timestamp(因为 embed 对您的引用对象)。