Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wzpan
Created August 20, 2013 12:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wzpan/6280559 to your computer and use it in GitHub Desktop.
Save wzpan/6280559 to your computer and use it in GitHub Desktop.
Python - timestamp
import datetime
# 2012-12-15 10:14:51.898000
print datetime.datetime.utcnow()
# The now differs from utcnow as expected
# otherwise they work the same way:
# 2012-12-15 11:15:09.205000
print datetime.datetime.now()
# You can render the timestamp to the ISO format string explicitly:
# '2012-12-15 11:15:24.984000'
str(datetime.datetime.now())
# Or you can be even more explicit to format the
# timestamp the way you like:
# 'Saturday, 15. December 2012 11:19AM'
datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p")
# '2012-12-15'
datetime.datetime.now().strftime("%Y-%m-%d")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment