代码改变世界

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

2018-07-02 15:43  小娜_8337  阅读(5621)  评论(0)    收藏  举报

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