Last active
July 17, 2021 12:36
-
-
Save Mulperi/4ad49e2d585ff0424998217b26ac51e5 to your computer and use it in GitHub Desktop.
Python datetime and timestamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
# Create utc datetime object. | |
utcdatetime = datetime.datetime.utcnow() | |
print(utcdatetime) | |
# Create unix epoch timestamp from datetime. | |
milliseconds = int(datetime.datetime.timestamp(utcdatetime) * 1000) | |
timestamp = datetime.datetime.timestamp(utcdatetime) | |
print(milliseconds) | |
print(timestamp) | |
# Create datetime object from timestamp | |
datetime2 = datetime.datetime.fromtimestamp(timestamp) | |
print(datetime2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment