EN
Linux / Bash - print current Unix time in milliseconds
1
points
In this short article, we would like to show how to print unix time in milliseconds in Unix / Linux terminal.
Quick example:
date +%s%3N
Screenshot:
Alternatives
This section shows alternative solutions.
date +%s%N | cut -b 1-13
# or
echo $(($(date +%s%N) / 1000000))
Note: the first of the solutions above is not perfect as we have extracted
1-13
numbers which will change in the long term due to the increasing number representing time.
Some linux distributions and Unix based operating systems like OS X could do not upport %N
, so it can be necessary to use other solution to get it. Below description shows how to do it with different techniques.
Solutions table:
Language | Console command |
Ruby | ruby -e 'puts Time.now.to_f' |
Python | python -c 'import time; print time.time()' |
Node.js | node -e 'console.log(Date.now())' |
PHP | php -r 'echo microtime(TRUE);' |
Elixir | DateTime.utc_now() |> DateTime.to_unix(:millisecond) |
date rounded | date +%s000 |
Example time source for wget
and curl
: