Skip to content

Instantly share code, notes, and snippets.

@vanzaj
Created June 22, 2013 14:58
Show Gist options
  • Save vanzaj/5841176 to your computer and use it in GitHub Desktop.
Save vanzaj/5841176 to your computer and use it in GitHub Desktop.
from datetime import datetime
now = datetime.now()
codes = [
r'%Y-%m-%d %H:%M:%S',
r'%a %b %d %H:%M:%S',
r'%A %B %d',
r'%c',
r'%x %X %z %Z', # locale's date & time, UTC offset and timezone
]
print '%17s : %s' % ('code', 'result')
print '-'*17, ':', '-'*17
for c in codes:
print '%17s : %s' % (c, now.strftime(c))
@vanzaj
Copy link
Author

vanzaj commented Jun 22, 2013

$ python datetime_fmt.py
             code : result
----------------- : -----------------
%Y-%m-%d %H:%M:%S : 2013-06-22 22:58:58
%a %b %d %H:%M:%S : Sat Jun 22 22:58:58
         %A %B %d : Saturday June 22
               %c : Sat Jun 22 22:58:58 2013
      %x %X %z %Z : 06/22/13 22:58:58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment