Search code examples
linuxbashshelltime

Linux command to get time in milliseconds


How can I get time in milliseconds in a Bash shell script?


Solution

  • date +%s%N returns the number of seconds + current nanoseconds.

    Therefore, echo $(($(date +%s%N)/1000000)) is what you need.

    Example:

    $ echo $(($(date +%s%N)/1000000))
    1535546718115
    

    date +%s returns the number of seconds since the epoch, if that's useful.