首页 > 编程语言 > 详细

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

时间:2019-03-02 17:49:02      阅读:784      评论:0      收藏:0      [点我收藏+]
执行下面代码报错:
UnicodeEncodeError: ‘locale‘ codec can‘t encode character ‘\u5e74‘ in position 2: Illegal byte sequence

import time

print(time.strftime("%Y年%m月%d日 %H时%M分%S秒",time.localtime()))

报错原因为有中文字符,修改为下面代码即可

import time

print(time.strftime(‘%Y{y}%m{m}%d{d} %H{h}%M{f}%S{s}‘).format(y=‘年‘,m=‘月‘,d=‘日‘,h=‘时‘,f=‘分‘,s=‘秒‘))

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

原文:https://www.cnblogs.com/pinpin/p/10461581.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!