python 格式化时间含中文报错 UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2: Illegal byte sequence'
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='日')
人生苦短,我用python