Skip to content

Instantly share code, notes, and snippets.

@eculver
Created January 5, 2011 01:24
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save eculver/765777 to your computer and use it in GitHub Desktop.
Save eculver/765777 to your computer and use it in GitHub Desktop.
Basic conversion of python datetime to string and back
import datetime
fmt = '%Y%m%d%H%M%S' # ex. 20110104172008 -> Jan. 04, 2011 5:20:08pm
now_str = datetime.datetime.now().strftime(fmt)
now_datetime = datetime.datetime.strptime(now_str, fmt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment