gpt4 book ai didi

python - 如何将 datetime.date.today() 转换为 UTC 时间?

转载 作者:太空狗 更新时间:2023-10-29 17:12:38 27 4
gpt4 key购买 nike

如何确保将 datetime.date.today() 转换为 UTC 时间?

到目前为止,这是我的代码:

#today : 2014-12-21
today = datetime.date.today()

#1900-01-01 16:00:00+00:00
timeformat = datetime.datetime.strptime('16:00', '%H:%M').replace(tzinfo=pytz.utc)

#combine today and timeformat 2014-12-21 16:00:00
now = datetime.datetime.combine(u, timeformat.time())
str_now = now.strftime("%Y-%m-%d %H:%M:%S")

最佳答案

使用utcnow:

today = datetime.datetime.utcnow().date()

关于python - 如何将 datetime.date.today() 转换为 UTC 时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27587127/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com