zoukankan      html  css  js  c++  java
  • python时间操作—获取微秒级别的时间差

    python中有两个模块可以完成时间操作:time和datetime(相比较datetime更强大)
    以下分别是两个模块的具体信息:

    >>> dir(time)
    ['_STRUCT_TM_ITEMS', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'altzone', 'asctime', 'clock', 'ctime', 'daylight', 'get_clock_info', 'gmtime', 
    'localtime', 'mktime', 'monotonic', 'monotonic_ns', 'perf_counter', 'perf_counter_ns', 'process_time', 'process_time_ns', 'sleep', 'strftime', 'strptime',
    'struct_time', 'time', 'time_ns', 'timezone', 'tzname', 'tzset'] >>> dir(datetime.datetime) ['__add__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__',
    '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__sizeof__',
    '__str__', '__sub__', '__subclasshook__', 'astimezone', 'combine', 'ctime', 'date', 'day', 'dst', 'fold', 'fromisoformat', 'fromordinal', 'fromtimestamp', 'hour',
    'isocalendar', 'isoformat', 'isoweekday', 'max', 'microsecond', 'min', 'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime', 'strptime', 'time',
    'timestamp', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple', 'weekday', 'year']

     

    如果要获取微秒级别的时间差,可以利用以下代码

    import datetime
    begin_time = datetime.datetime.now()
    end_time = datetime.datetime.now()
    d_time = end_time - begin_time

    再看下 d_time 的属性和方法

    >>> dir(k)
    ['__abs__', '__add__', '__class__', '__delattr__', '__div__', '__doc__', '__eq__', '__floordiv__', '__format__', '__ge__', 
    '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__mul__', '__ne__', '__neg__', '__new__', '__nonzero__',
    '__pos__', '__radd__', '__rdiv__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rmul__', '__rsub__', '__setattr__',
    '__sizeof__', '__str__', '__sub__', '__subclasshook__', 'days', 'max', 'microseconds', 'min', 'resolution', 'seconds', 'total_seconds']

    以上是 d_time 所有的属性和函数
    利用以下代码可以获取以秒为单位的时间差,小数点后6位为微秒。


    ————————————————
    原文链接:https://blog.csdn.net/Dave_2010/article/details/60969261

  • 相关阅读:
    Delphi 操作Flash D7~XE10都有 导入Activex控件 shockwave
    TComboBoxEx和 TComboBox
    TScrollBox的用法 滚动事件
    虚拟树DemosMinimal 简单的例子
    窗体showModal
    B窗体继承于A窗体,B启动:问题点
    C# 读本地INI文件方法
    salesforce 零基础学习(二十九)Record Types简单介绍
    salesforce 零基础学习(二十八)使用ajax方式实现联动
    salesforce 零基础学习(二十七)VF页面等待(loading)效果制作
  • 原文地址:https://www.cnblogs.com/sunshine-blog/p/12599403.html
Copyright © 2011-2022 走看看