Skip to content

Instantly share code, notes, and snippets.

@josepsmartinez
Forked from wzpan/timestamp.py
Last active May 10, 2022 17:41
Show Gist options
  • Save josepsmartinez/48e89ae63f66ea1b44cdb72650f352a7 to your computer and use it in GitHub Desktop.
Save josepsmartinez/48e89ae63f66ea1b44cdb72650f352a7 to your computer and use it in GitHub Desktop.
Python datetime timestamps
import datetime
# ISO formatting
datetime.datetime.utcnow() # ('2022-05-10 04:18:09.297644')
datetime.datetime.now() # ('2022-05-10 01:18:09.297743')
# Custom formatting
## Pretty ('Saturday, 15. December 2012 11:19AM')
datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p")
## Calendar ('2012-12-15')
datetime.datetime.now().strftime("%Y-%m-%d")
## Minimal string ('20220510011809297880')
datetime.datetime.now().strftime("%Y%m%d%H%M%S%f")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment