2015-10-16

[SOLVED]How to get system time with microsecond Resolution

#13:24 13/07/2015
################
#Hien thi thoi gian, chinh xac den don vi phan trieu giay (nanoseconds)
now="$(date +'%Y.%m.%d-%H.%M.%S.%6N')"
echo $(date +'%Y.%m.%d-%H.%M.%S.%6N')
echo $(date +'%Y.%m.%d-%H.%M.%S.%6N')


#To get the micro seconds just do an eval
expr `date +%s%N` / 1000
http://unix.stackexchange.com/questions/204796/how-to-get-system-time-with-microsecond-resolution

or:

date +%s returns the number of seconds since the epoch.
date +%s%N returns the number of seconds + current nanoseconds.
echo $(( $(date +%s%N)/1000000 ))
#
date +"%T.%N" returns the current time with nanoseconds.
#
date +"%T.%6N" returns the current time with nanoseconds rounded to the first 6 digits, which is microseconds.
echo $(date +"%T.%6N")
Result: 10:26:27.054181
#
date +"%T.%3N" returns the current time with nanoseconds rounded to the first 3 digits, which is milliseconds.
#
In general, every field of the date command's format can be given an optional field width.
#
http://stackoverflow.com/questions/16548528/linux-command-to-get-time-in-milliseconds

No comments:

Post a Comment