Last active
June 28, 2022 11:00
-
-
Save lyf-is-coding/01a31ff7267cab2788fab9ac58b9ae3a to your computer and use it in GitHub Desktop.
Python convert timestamp to date time
This file contains hidden or 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
| from datetime import datetime | |
| def timestamp_to_datetime(timestamp : float, format : str): | |
| try: | |
| date = datetime.fromtimestamp(timestamp).strftime(format) | |
| return date | |
| except: | |
| timestamp /= 1000 | |
| date = datetime.fromtimestamp(timestamp).strftime(format) | |
| return date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment