中文日期时间显示
四行代码就可以。
import time
loc_s = time.localtime()
s_tuple = ('年', '月', '日 ', ':', ':', '')
for x, y in zip(loc_s, s_tuple): print(str(x)+y, end='')
也可以让显示好看点😜
代码
#! /sur/bin/nve python
# coding: utf-8
import time
'''显示当前时间'''
#打印分割线
print('\n'+'﹊'*21)
#获取当前时间元组
loc_s = time.localtime()
#格式打印字符元组
s_tuple = ('年', '月', '日 ', ':', ':', '')
#打印显示前导空格的字符串
print(''.rjust(10), end='')
for x, y in zip(loc_s, s_tuple):
print(str(x)+y, end='')
print('\n'+'﹊'*21)
显示效果
![老齐漫画头像](https://i-blog.csdnimg.cn/blog_migrate/8cbf2c45d8b57205b31ef4963b3b9854.jpeg)