Skip to content

Instantly share code, notes, and snippets.

@teleprint-me
Created November 28, 2022 01:46
Show Gist options
  • Save teleprint-me/c644ccdeaf0b064448184b3846cab3ad to your computer and use it in GitHub Desktop.
Save teleprint-me/c644ccdeaf0b064448184b3846cab3ad to your computer and use it in GitHub Desktop.
Simplify timestamps in python
from datetime import date, datetime
from dateutil import parser
def to_datetime(value: str) -> datetime:
return parser.parse(value)
def to_iso(value: datetime) -> str:
return value.isoformat()
def to_date(value: str) -> str:
return date.isoformat(parser.parse(value))
def timestamp() -> str:
return datetime.now().isoformat()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment