• 标准库datetime


    1、datetime模块

      对日期,时间,时间戳的处理

      datetime类:

        类方法:

           today()返回本地时区当前时间的datetime对象

           now(tz=None)返回当前时间的datetime对象,时间到微秒,如果tz为None,返回和today()一样

           utcnow()没有时区的当前时间

           fromtimestamp(timestamp,tz=None)从一个时间戳返回一个datetime对象

        datetime对象:

           timestamp()返回一个到微秒的时间戳

              时间戳:格林威治时间1970年1月1日0点到现在的秒数

    2)、datetime对象

        构造方法datetime.datetime(2016.2.1)

        year、month、day、hour、minute、second、microsecond,取datetime对象的年月日时分秒以及微秒

        weekday()返回星期的天、周一0、周日6

        isoweekday()返回星期的天,周一1,周日7

        date()返回日期date()对象

        time()返回时间time对象

        replace()修改并返回新的时间

        ioscalendar()返回一个三元组(年、周数、周的天)

    3)、日期格式化

        类方法strptime(date_string,format),返回datetime对象;对象方法strftime(format),返回字符串;字符串format函数格式化

    例: 

    import datetime

    dt=datetime.datetime.striptime("21/11/06 16:30","%d/%m/%y/%H:%M")

    print(dt.strftime("%Y-%m-%d %H:%M:%S"))

    print("{0:%Y}/{0:%m}/{0:%d} {0:%H}::{0:%M}::{0:%S}".format(dt) 

    4)、timedelta对象

      datetime2=datetime1+timedelta

      datetime2=datetime1-timedelta

      timedelta=datetime1-datetime2

      构造方法

          datetime.timedelta(days=0,second=1,microseconds=0,milliseconds=0,minutes=0,hours=0,weeks=0)

    year=datetime.timedelta(days=365)

      total_seconds()返回时间差的总秒数

      time.sleep(secs)将调用线程挂起指定的秒数

  • 相关阅读:
    项目无法运行iPhone5模拟器
    多线程下载图片,滑动tableView崩溃--资源抢夺问题
    提醒事项 1. 冥想TX 2.下班路上听歌激励自己 3. 不戴眼镜 4. 困难任务拆解
    AutoLayout性能不如frame
    Tunnelblick 覆盖安装失败
    weakSelf 和 strongSelf
    动画
    4/16 近期状态
    知乎live 我的读书经验 总结
    C语言-第23课
  • 原文地址:https://www.cnblogs.com/mapone/p/12050293.html
Copyright © 2020-2023  润新知