跳转至

创建亚秒级精度的时间戳

原文链接: https://www.nv5geospatialsoftware.com/Learn/Blogs/Blog-Details/creating-timestamps-with-sub-second-accuracy

16154 为本文评分:

5.0

创建亚秒级精度的时间戳

匿名 2014年8月28日 星期四

当您需要写入日志文件并按时间顺序对多个文件的条目进行排序时,IDL 中的 TIMESTAMP 函数非常好用。然而,一个常见的问题是,当代码运行很快时,位数会不够用。这个替代例程展示了如何将时间戳精度提高到几分之一秒。在 Windows 上,"systime"通常限制在大约 1 毫秒。但在 Linux 上,精度可以接近 1 微秒。

以下是标准 TIMESTAMP 函数与改进精度后的 TIMESTAMP2 函数输出的比较。

ENVI> print,(t=timestamp()) & for i=0, 299 do if t ne timestamp() then print, (t=timestamp())

2014-08-27T21:31:30.00004827976228Z

ENVI> print,(t=timestamp2()) & for i=0, 299 do if t ne timestamp2() then print, (t=timestamp2())

2014-08-27T21:31:41.808

2014-08-27T21:31:41.809

2014-08-27T21:31:41.810

2014-08-27T21:31:41.811

2014-08-27T21:31:41.812

2014-08-27T21:31:41.813

2014-08-27T21:31:41.814

2014-08-27T21:31:41.815

2014-08-27T21:31:41.816

2014-08-27T21:31:41.817

在此案例中,在 Windows 7 操作系统上运行时,TIMESTAMP2 的更新速率约为 1 毫秒。以下是 TIMESTAMP2 函数的源代码清单:

*function* timestamp2**

compile_opt idl2,logical_predicate

t = systime(1)

str = systime(0, floor(t), /utc)

td = 0d

reads, str, td, format='(c())'

td += (t-floor(t))/(24*3600d)

tstr = string(td, format='(c(cyi4.4,"-",cmoi2.2,"-",cdi2.2,"T",cHi2.2,":",cmi2.2,":",csf06.3))')

return, tstr

end**

从过去到现在的态势感知 卫星图像证实苏丹危机再起