Languages
[Edit]
EN

Linux / Bash - print current Unix time in milliseconds

1 points
Created by:
Root-ssh
177620

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:

Milliseconds time in Linux / Unix Bash.
Milliseconds time in Linux / Unix Bash.

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: 

LanguageConsole command
Rubyruby -e 'puts Time.now.to_f'
Pythonpython -c 'import time; print time.time()'
Node.jsnode -e 'console.log(Date.now())'
PHPphp -r 'echo microtime(TRUE);'
ElixirDateTime.utc_now() |> DateTime.to_unix(:millisecond)
date roundeddate +%s000

Example time source for wget and curl:

  1. https://currentmillis.com/

 

Alternative titles

  1. Linux / Bash - millisecond time in unix terminal
  2. Linux / Bash - print current Unix timestamp in milliseconds
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Linux

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join