本文共 733 字,大约阅读时间需要 2 分钟。
import datetimeimport time'''datetime比time高级了不少,可以理解为date time基于time进行了封装,提供了各种实用的函数,date time模块的接口更为直观,更容易调用模块中的类:datetime 同时有时间和日期timedelta 主要用于计算时间跨度tzinfo 时区相关time 只关注时间date 只关注日期'''#获取当前时间d1 = datetime.datetime.now()print(d1)#d2 = datetime.datetime(1995, 4, 28,10,23,34,123355)print(d2)#d3 = datetime.datetime.time(d1)print(d3)#将时间转换为字符串#d4 = d1.strptime("%Y-%m-%d %X")#print(d4)#时间加减d5 = d1 - d2print(d5)#间隔的天数print(d5.days)#间隔天数除外的秒数print(d5.seconds)
import calendar'''日历'''#使用print(calendar.month(2019, 7))#返回指定年的日历print(calendar.calendar(2019))#判断闰年,返回Trueprint(calendar.isleap(2000))#返回某个月的weekday的第一天和这个月的天数print(calendar.monthrange(2018, 12))#返回某个月以每一周为元素的列表print(calendar.monthcalendar(2017, 12))
转载地址:http://smhal.baihongyu.com/