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='日')


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM