Skip to content

Instantly share code, notes, and snippets.

@colehocking
Created May 15, 2025 14:27
Show Gist options
  • Save colehocking/7ac91460d91b2106de1a08858c548cac to your computer and use it in GitHub Desktop.
Save colehocking/7ac91460d91b2106de1a08858c548cac to your computer and use it in GitHub Desktop.
Convert a Unix timestamp in Python
from datetime import datetime
def convertTime(unix_timestamp):
"""
:return datetime obj
"""
try:
date_object = datetime.strptime(unix_timestamp, '%Y-%m-%dT%H:%M:%Sz')
return date_object
except ValueError:
print("Object: %r is type: %r" % (unix_timestamp, type(unix_timestamp))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment