Skip to content

Instantly share code, notes, and snippets.

@lyf-is-coding
Last active June 28, 2022 11:00
Show Gist options
  • Select an option

  • Save lyf-is-coding/01a31ff7267cab2788fab9ac58b9ae3a to your computer and use it in GitHub Desktop.

Select an option

Save lyf-is-coding/01a31ff7267cab2788fab9ac58b9ae3a to your computer and use it in GitHub Desktop.
Python convert timestamp to date time
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