python对于时间的抽象

datetime.date 包含year, month, day的日期

    核心api:

        date.fromtimestamp(timestamp) 从时间戳来构造

        timetuple() 生成时间数据结构 

time.struct_time((year, month, day, 0, 0, 0, d.weekday(), yday, -1))

        date.strftime(format)  格式化输出

        ordinal 距离(1,1,1)的天数

datetime.datetime 扩展date添加了

    now()

   datetime.strptime(date_string, format)

   datetime.astimezone(tz)

   strftime 输出字符串

   strptime 从字符串生成对象

datetime.time 

    包括年月日 时区信息(tzinfo 一般包括时区,是否夏令时等)

time 对应c语言中的时间模块

time.asctime([t]) 返回字符串'Fri Feb 10 14:34:09 2017'

time.ctime([secs])  返回字符串'Fri Feb 10 14:34:09 2017'

time.gmtime([secs]) 将自epoch 以来的时间秒数转换为UTC 的struct_time,

time.localtime([secs])  转成当地时间 struct_time

time.mktime(t)  生成时间戳

time.strftime(format[, t])  time.strptime(string[, format]) 字符串与time_struct  之间的转换

time.struct_time

    包含多个属性的元组

猜你喜欢

转载自eric-weitm.iteye.com/blog/2356486