简体   繁体   English

以 12 小时格式转换 UTC 时间

[英]Convert UTC time in 12 hours format

I have a discord bot.我有一个不和谐的机器人。 There is function in that bot, which returns when the member has joined the server.该机器人中有函数,当成员加入服务器时返回。 But the time is in UTC format.但是时间是UTC格式。 I just want to convert that UTC time in 12 hour clock format also using the UTC time zone of my country.我只想使用我所在国家/地区的 UTC 时区以 12 小时时钟格式转换该 UTC 时间。

Is there any way to do this?有没有办法做到这一点?

You can use datetime to format date string.您可以使用datetime来格式化日期字符串。

datetime.strftime("%Y-%m-d %I:%S %p") #2020-09-09 11:54 AM

%I for 12 hour time format and %p to display AM or PM %I 表示 12 小时时间格式,%p 表示 AM 或 PM

You can refere datetime docs for more understanding您可以参考日期时间文档以获得更多理解

You can also add %z or %Z to display timezone as per your requirement您还可以根据需要添加 %z 或 %Z 以显示时区

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM