python 格式化时间含中文报错 'locale' codec can't encode character '\u5e74'



import
time print(time.strftime('%Y年%m月%d日 %H时%M分%S秒'))

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

 

解决方式:

time.strftime('%Y{y}%m{m}%d{d} %H{h}%M{f}%S{s}').format(y='',m='',d='',h='',f='',s='')

 


免责声明!

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



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