linux shell 獲取毫秒數 計時

%m month (01..12)ide

%M minute (00..59)ui

%n a newlineit

%N nanoseconds (000000000..999999999)class

%p locale’s equivalent of either AM or PM; blank if not knowndate

%P like %p, but lower caseim

%r locale’s 12-hour clock time (e.g., 11:11:04 PM)margin

%R 24-hour hour and minute; same as %H:%Mtop

%s seconds since 1970-01-01 00:00:00 UTCdi

%S second (00..60)view

%n就是納秒數,%s是1970以來的秒數,若是隻是想要毫秒就本身cut一下就ok了。

1秒s = 1000 毫秒ms

1毫秒ms = 1000 微秒us

1微秒us = 1000 納秒ns

1納秒ns = 1000 皮秒ps

1毫秒 就等於 1000 * 1000 納秒

下面這個我是懶得cut了,直接除以以一百萬就是了。

cat count.sh

START=`date +%s%N`;sleep 3;END=`date +%s%N`;echo `expr \( $END – $START \) / 1000000`

相關文章
相關標籤/搜索