Python-datetime

datetime库

datetime库下的类
datetime.date:日期表示类,可以表示年月日等。
datetime.time:时间表示类,可以以时分秒毫秒表示。
datetime.datetime:日期时间有关的类,功能覆盖date和time类。
datetime.timedelta:有时间间隔有关的类。
datetime.tzinfo:与时区相关的信息表示类。

1、datetime.datetime()

常用属性:

.min:返回datetime最小时间对象。
.max:返回datetime最大时间对象。
.year:datetime对象的年属性值。
.month:datetime对象的月属性值。
.day:datetime对象的日属性值。
.hour:datetime对象的时属性值。
.minute:datetime对象的分属性值。
.second:datetime对象的属性值。秒
.microsecond:datetime对象的微秒属性值。

创建对象:

datetime.datetime.now():以当前日期和时间作为属性值,可精确到微秒。
datetime.datetime.utcnow():以当前日期和时间作为属性值,可精确到微秒,以UTC(世界标准时间)表示时间日期。
datetime.datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0):至少指定年月日创建对象。

常用方法

.isoformat():采用ISO 0861标准显示时间,并返回字符串。

.isoweekday:根据日期计算星期并返回(1-7,整型)。

.strftime(format):根据格式化字符串format进行格式化显示,并返回字符串。格式化控制符号如下:

posted @ 2022-12-18 17:24  Fanslyx  阅读(68)  评论(0)    收藏  举报