Dave's Brain

Browse - Programming Tips - How can I get the millisecond since the epoch?

Date: 2017may10
OS: Linux
Language: bash

Q.  How can I get the millisecond since the epoch?

A.  Use the + option of the date command.

%s is the seconds %N is the nanoseconds %3N is the first 3 digits of the nanoseconds (doesn't work on all systems)
So:
date '+%s%3N' If %3N works for you
Otherwise:
$(( $(date +%s%N) / 1000000 ))

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.