中文时间日期解析错误-UnicodeEncodeError: ‘locale’ codec can’t encode character ‘\u5e74’ in position 2: Illegal

2022年6月6日11:47:44

参考:https://segmentfault.com/q/1010000003070325

       word = (datetime.today() + timedelta(days=keyDate.get(k, 0))).strftime('%Y年%m月%d日')

报错:“UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2: Illegal byte sequence“”

更改为:
   word = (datetime.today() + timedelta(days=keyDate.get(k, 0))).strftime('%Y{y}%m{m}%d{d}').format(y='年', m='月', d='日')

  • 作者:旺仔的算法coding笔记
  • 原文链接:https://blog.csdn.net/wangwangstone/article/details/86480466
    更新时间:2022年6月6日11:47:44 ,共 341 字。