I have due_by
as a local datetime
object the following solutions isn't working for me!
due_by = float(due_by.strftime("%s"))
due_by = datetime.utcfromtimestamp(due_by)
Thanks in advance!
I have due_by
as a local datetime
object the following solutions isn't working for me!
due_by = float(due_by.strftime("%s"))
due_by = datetime.utcfromtimestamp(due_by)
Thanks in advance!
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)