Command to get time in milliseconds

MOHAMED picture MOHAMED · May 14, 2013 · Viewed 383.9k times · Source

Is there a shell command in Linux to get the time in milliseconds?

Answer

Michael Defort picture Michael Defort · Sep 9, 2013
  • date +"%T.%N" returns the current time with nanoseconds.

    06:46:41.431857000
    
  • date +"%T.%6N" returns the current time with nanoseconds rounded to the first 6 digits, which is microseconds.

    06:47:07.183172
    
  • date +"%T.%3N" returns the current time with nanoseconds rounded to the first 3 digits, which is milliseconds.

    06:47:42.773
    

In general, every field of the date command's format can be given an optional field width.