如何将Python time.monotonic准确转换为walltime

问题描述 投票:0回答:1

我有一个由

time.monotonic()
返回的时间,我想将其转换为墙上时间(即
time.time()
,适合使用
time.strftime
进行格式化)。有没有一种精确/原子的方法来获得两者之间的偏移量?我知道我可以在任意时间点请求
time.monotonic()
time.time()
并计算差异,但这是不准确的,因为两个调用之间会有一些延迟(因为 Python 很慢,所以延迟会更多,如果碰巧有中断/重新安排)。

python time
1个回答
0
投票

导入时间

baseline_monotonic = time.monotonic() 基线_墙时间 = time.time()

def monotonic_to_walltime(monotonic_timestamp):

diff = monotonic_timestamp - baseline_monotonic

estimated_walltime = baseline_walltime + diff

return estimated_walltime
© www.soinside.com 2019 - 2024. All rights reserved.