python 格式化时间含中文报错 UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2: Illegal byte sequence'

import time

print(time.strftime(u'%Y年%m月%d日',time.localtime(time.time())))

执行上面代码会报错  UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2: Illegal byte sequence


解决方式:
time.strftime('%Y{y}%m{m}%d{d}').format(y='年',m='月',d='日')
posted @ 2018-09-16 23:59  kennyhip  阅读(7145)  评论(0编辑  收藏  举报