Linux / Bash - print current Unix time in milliseconds

1 points
Created by:

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


millisecond time in Linux / Unix Bash
millisecond time in Linux / Unix Bash


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'
Pythonpython -c 'import time; print time.time()'
Node.jsnode -e 'console.log('
PHPphp -r 'echo microtime(TRUE);'
ElixirDateTime.utc_now() |> DateTime.to_unix(:millisecond)
wget + internetuse wget to download time
curl + linkuse curl to download time
date roundeddate +%s000

Example time source for wget and curl:

Hey ūüĎč
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.