这些个小东西对于文件的记录,log的输出等还是很有用的,先获取了再说:
# -*- coding: utf-8 -*-
import calendar
import datetime
"""
%y 2个数字表示年份
%Y 4个数字表示年份
%b 月份的简写。一月:Jan
%B 月份的全写。一月:January
%m 月份[01,12]
%d 日在这个月中的天数(这个月的第几天)
%H 24小时制
%h 12小时制
%M 分钟[00,59]
%S 秒[00,61]
%f 微秒
%a 星期的简写。星期一 : Mon
%A 星期的全写。星期一 :Monday
%c 日期时间的字符串表示。'Mon Jan 14 00:00:00 2019'
%x 日期字符串
%X 时间字符串
%j 日在年中的天数[001,366]
%U 在当年的第几周,星期天作为周的第一天
%w 今天在这周的第几天[0,6],6表示星期天
%W 是当年的第几周,星期一作为周的第一天
"""
# 显示日历 2021年11月份
print("total %d days" % calendar.monthrange(2021,11)[1])
print(calendar.month(2021,11))
# 显示昨天 今天 明天
today = datetime.date.today()
deltadays = datetime.timedelta(days=1)
yesterday = today-deltadays
tomorrow = today+deltadays
print(yesterday)
print(today)
print(tomorrow)
now = datetime.datetime.now()
print(now)
otherStyleTime = now.strftime("%Y-%m-%d %H:%M:%S")
print(otherStyleTime)
otherStyleTime = now.strftime("%Y-%b-%d %H:%M:%S")
print(otherStyleTime)
otherStyleTime = now.strftime("%Y-%m-%d %H:%M:%S.%f")
print(otherStyleTime)
otherStyleTime = now.strftime("%x")
print(otherStyleTime)
otherStyleTime = now.strftime("%X")
print(otherStyleTime)