![](/img/trans.png)
[英]How to convert UTC datetime to local datetime (Australia/Melbourne) in Python
[英]How can i convert a python local datetime object to utc
我將due_by
作為本地datetime
對象,以下解決方案對我不起作用!
due_by = float(due_by.strftime("%s"))
due_by = datetime.utcfromtimestamp(due_by)
提前致謝!
from datetime import datetime
from datetime import timezone
# Datetime to timestamp
t = datetime.now()
due_by = t.timestamp()
# 1600261731.016313
print(due_by)
# Timestamp to datetime
due_by = datetime.fromtimestamp(due_by, tz=timezone.utc)
# 2020-09-16 13:08:51.016313+00:00
print(due_by)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.