shell里输出年月日时分秒的话、这样写,
echo 'date +%Y/%m/%d%t%H:%M:%S%t'
如果想继续输出 毫秒 微妙 该怎么写
shell里输出年月日时分秒的话、这样写,
echo 'date +%Y/%m/%d%t%H:%M:%S%t'
如果想继续输出 毫秒 微妙 该怎么写
如解决,望采纳,代码如下:
#!/bin/sh
function getTiming(){
start=$1
end=$2
start_s=`echo $start| cut -d '.'-f 1`
start_ns=`echo $start| cut -d '.'-f 2`
end_s=`echo $end| cut -d '.'-f 1`
end_ns=`echo $end| cut -d '.'-f 2`
time_micro=$(( (10#$end_s-10#$start_s)*1000000 + (10#$end_ns/1000 - 10#$start_ns/1000) ))
time_ms=`expr $time_micro/1000 | bc `
echo "$time_micro microseconds"
echo "$time_ms ms"
}
begin_time=`date +%s.%N`
sleep10
end_time=`date +%s.%N`
getTiming $begin_time$end_time