python - ValueError: zero length field name in format -


i trying convert date nice format using below code , runninginto following error..can provide inputs on how overcome here?

from datetime import datetime d = datetime.fromtimestamp(1372058963) print d create_date = datetime.strptime(str(d), '%y-%m-%d %h:%m:%s') print create_date gerrit_created_date = "{}/{}/{}".format(create_date.month,create_date.day,create_date.year) print gerrit_created_date 

error:-

  file "test.py", line 7, in <module>     gerrit_created_date = "{}/{}/{}".format(create_date.month,create_date.day,create_date.year) valueerror: 0 length field name in format 

better use datetime.strftime:

>>> d = datetime.fromtimestamp(1372058963) >>> datetime.strftime(d, '%m/%d/%y') '06/24/2013' >>> datetime.strftime(d, '%m/%d/%y %h:%m:%s') '06/24/2013 12:59:23' 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -