时间日期差异以微秒为单位

时间:2011-11-21 06:17:42

标签: python datetime

我是Python的新手,我在计算两次之间的差异时遇到了问题。

我有一个文件,其中包含一个列表,其中包含特定邮件留下的时间和邮件重新出现的时间。每个邮件都显示在不同的行上。每个都以微秒记录。我想找到两者之间的差异并打印结果。

非常感谢帮助我!对此,我真的非常感激。

1 个答案:

答案 0 :(得分:0)

一般程序包括首先阅读文件,例如:

with open('/path/to/file') as input_file:
    for line in input_file:
        # 'line' is the contents of each line (including line termination characters)
        # ... the strings representing the times are obtained here ...

然后可以使用

完成以微秒为单位的计算
int(time1_string)-int(time0_string)

类型转换很重要(它将一串字符转换为数字,以便可以对其执行数学运算)。

相关问题