小码问答,有问必答!

2021-01-06 10:52

t.strftime('%m月%d %H:%M')出现中文报错

牛叔叔 2021-01-06 10:52 回答了这个问题

Python

 t.strftime('%m月%d %H:%M')

<class 'datetime.datetime'>

Traceback (most recent call last):

  File "D:/pythonworks/xinkongxinxi1/comment_dao.py", line 28, in <module>

    tstr = t.strftime('%m月%d %H:%M')

UnicodeEncodeError: 'locale' codec can't encode character '\u6708' in position 2: encoding error


#格式化时间不能有中文,如果想要中文需要设置
import locale
locale.setlocale(locale.LC_CTYPE,'chinese')


0条评论

我要评论