%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%p locale’s equivalent of either AM or PM; blank if not known
%P like %p, but lower case
%r locale’s 12-hour clock time (e.g., 11:11:04 PM)
%R 24-hour hour and minute; same as %H:%M
%s seconds since 1970-01-01 00:00:00 UTC
%S second (00..60)
…
%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`