linux shell毫秒计时


man date

%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以来的秒数
1毫秒 等于 1000 * 1000 纳秒


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

你可能感兴趣的:(Shell)