Python获得时间与星期

想用Python给出现在的时间信息:年月日和星期几,查了一下,下面的代码是比较方便的

from datetime import datetime
import time

report_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
week_dict = {1: '星期一', 2: '星期二', 3: '星期三', 4: '星期四', 5: '星期五', 6: '星期六', 0: '星期天'}
d = week_dict.get(datetime.today().isoweekday())
report_time = str(report_time) + ' ' + str(d)
print('### report_time is {}'.format(report_time))

结果:

猜你喜欢

转载自blog.csdn.net/whuzhang16/article/details/109812068
今日推荐