#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from datetime import datetime
nt=datetime.now()
print(nt.strftime('%Y年%m月%d日 %H时%M分%S秒'))
为何里面不能使用中文?用英文字符没事,但是只要用中文就报错
Traceback (most recent call last):
File "test.py", line 6, in
print(nt.strftime('%Y年%m月%d日 %H时%M分%S秒'))
UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2
: Illegal byte sequence
网上找遍了,关于python的格式化时间的使用,全部用的英文格式,就没人用中文?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
print(nt.strftime('%Y年%m月%d日 %H时%M分%S秒').decode('utf-8'))#正常输出2015年08月10日 11时25分04秒