Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中获取时间戳差异的方法_Python_Linux - Fatal编程技术网

python中获取时间戳差异的方法

python中获取时间戳差异的方法,python,linux,Python,Linux,我试图测量引导加载程序计时,在这里我需要测量SPL、U-Boot和总时间(SPL+U-Boot)。我的minicom控制台日志条目如下所示 现在 SPL启动时间为:第1行和第2行的时间戳差异(SPL启动和 U-Boot启动) U-Boot引导时间为:第2行和第2行的时间戳差异 第3行(U-Boot启动和启动内核) 总时间为:时间戳 1号线和3号线的差异 我看到python支持年、月、日、小时、分钟、秒、微秒、毫秒,但不确定如何将此时间戳转换为timedelta。我正在学习python,所以想在

我试图测量引导加载程序计时,在这里我需要测量SPL、U-Boot和总时间(SPL+U-Boot)。我的minicom控制台日志条目如下所示

现在

SPL启动时间为:第1行和第2行的时间戳差异(SPL启动和 U-Boot启动)
U-Boot引导时间为:第2行和第2行的时间戳差异 第3行(U-Boot启动和启动内核)
总时间为:时间戳 1号线和3号线的差异


我看到python支持年、月、日、小时、分钟、秒、微秒、毫秒,但不确定如何将此时间戳转换为timedelta。我正在学习python,所以想在那里尝试一下。有人能建议怎么做吗。我必须对多个产品和多个版本的bootloader进行这些度量,因此编写脚本将是一件好事。

这通过使用非常简单,只需要确保使用正确的格式

请参阅可用的指令


通过使用,这非常简单,只需确保使用正确的格式

请参阅可用的指令


你是在问如何计算2018-10-11 15:05:11.021和2018-10-11 15:05:11.294之间的差异吗?是的,它们之间的差异。你是在问如何计算2018-10-11 15:05:11.021和2018-10-11 15:05:11.294之间的差异吗?是的,它们之间的区别。
%f
不是毫秒而是微秒吗?我提到的时间戳中有毫秒。所以我需要使用其他格式,对吗?
%f
不是毫秒而是微秒吗?我提到的时间戳中有毫秒。所以我需要使用其他格式,对吗?
$ cat u-boot-2017-01 | grep -e 'U-Boot SPL 2017' -e 'U-Boot 2017.01' -e 'Starting kernel ...'
[2018-10-11 15:05:11.021] U-Boot SPL 2017.01-05786-ge0aa2fcb13 (Oct 10 2018 - 13:53:01)
[2018-10-11 15:05:11.294] U-Boot 2017.01-05786-ge0aa2fcb13 (Oct 10 2018 - 13:53:01 -0400)
[2018-10-11 15:05:12.706] Starting kernel ...
from datetime import datetime

start_time = '2018-10-11 15:05:11.021'
end_time = '2018-10-11 15:05:11.294'

FORMAT = '%Y-%m-%d %H:%M:%S.%f'

print(datetime.strptime(end_time, FORMAT) - datetime.strptime(start_time, FORMAT))
# 0:00:00.273000