Linux中是否有shell命令以毫秒为单位获取时间?


当前回答

Nano是10−9,milli是10−3。因此,我们可以使用纳秒的前三个字符来得到毫秒:

date +%s%3N

男人约会:

%N纳秒(000000000..999999999) 1970-01-01 00:00:00 UTC以来的%s秒

来源:服务器故障如何在Bash中以毫秒为单位获得当前Unix时间?

其他回答

Nano是10−9,milli是10−3。因此,我们可以使用纳秒的前三个字符来得到毫秒:

date +%s%3N

男人约会:

%N纳秒(000000000..999999999) 1970-01-01 00:00:00 UTC以来的%s秒

来源:服务器故障如何在Bash中以毫秒为单位获得当前Unix时间?

像这样的Python脚本:

import time
cur_time = int(time.time()*1000)

用时间和时区显示日期

日期+"%d-%m-%Y %T "。% N % Z”

输出22

当你从4.1版本开始使用GNU AWK时,你可以加载时间库并执行以下操作:

$ awk '@load "time"; BEGIN{printf "%.6f", gettimeofday()}'

这将以秒为单位打印自1970-01-01T00:00:00以来的当前时间,精度为亚秒。

the_time = gettimeofday() Return the time in seconds that has elapsed since 1970-01-01 UTC as a floating-point value. If the time is unavailable on this platform, return -1 and set ERRNO. The returned time should have sub-second precision, but the actual precision may vary based on the platform. If the standard C gettimeofday() system call is available on this platform, then it simply returns the value. Otherwise, if on MS-Windows, it tries to use GetSystemTimeAsFileTime(). source: GNU awk manual

在Linux系统上,标准C函数getimeofday()以微秒精度返回时间。

日期+“% T。%N"返回当前时间,单位为纳秒。 06:46:41.431857000 日期+“% T。%6N”返回当前时间,其中纳秒四舍五入到前6位数字,即微秒。 06:47:07.183172 日期+“% T。%3N”返回当前时间,将纳秒四舍五入到前3位数字,即毫秒。 06:47:42.773

通常,date命令格式的每个字段都可以指定可选的字段宽度。