python中的时间操作

###参考文章

  • datetime<->timestamp

    一.time模块
    time模块提供各种操作时间的函数
    一般有两种表示时间的方式:
    第一种: 是时间戳的方式(相对于1970.1.1 00:00:00以秒计算的偏移量),时间戳是惟一的
    第二种: 以数组的形式表示即(struct_time),共有九个元素,分别表示,同一个时间戳的struct_time会因为时区不同而不同

    二.datetime模块
    Python提供了多个内置模块用于操作日期时间,像calendar,time,datetime。time模块。
    相比于time模块,datetime模块的接口则更直观、更容易调用。
    datetime模块定义了下面这几个类:
    datetime.date:表示日期的类。常用的属性有year, month, day;
    datetime.time:表示时间的类。常用的属性有hour, minute, second, microsecond;
    datetime.datetime:表示日期时间。
    datetime.timedelta:表示时间间隔,即两个时间点之间的长度。
    datetime.tzinfo:与时区有关的相关信息。
    datetime中,表示日期时间的是一个datetime对象
    datetime中提供了strftime方法,可以将一个datetime型日期转换成字符串: