What is Unix time?
How do I get the current Unix time in JavaScript?
How do I get the current Unix time in Python?
Videos
If you want milliseconds instead of nanoseconds precision, you might use %3N instead of %N:
$ date +'%d/%m/%Y %H:%M:%S:%3N'
12/04/2014 18:36:20:659
or with your desired use of $(β¦):
$ echo "$(date +'%d/%m/%Y %H:%M:%S:%3N')"
12/04/2014 18:36:20:659
But be aware, that %N may not implemented depending on your target system or bash version.
Tested on an embedded system Β»GNU bash, version 4.2.37(2)-release (arm-buildroot-linux-gnueabi)Β« there was no %N (neither %3N):
date +"%F %T,%N"
2014-01-08 16:44:47,%N
date +%x_%H:%M:%S:%N
if you need to print only two first nums as ms:
date +%x_%H:%M:%S:%N | sed 's/\(:[0-9][0-9]\)[0-9]*$/\1/'
to store it in the var:
VAR=$(date +%x_%H:%M:%S:%N | sed 's/\(:[0-9][0-9]\)[0-9]*$/\1/')
This:
date +%s
will return the number of seconds since the epoch.
This:
date +%s%N
returns the seconds and current nanoseconds.
So:
date +%s%N | cut -b1-13
will give you the number of milliseconds since the epoch - current seconds plus the left three of the nanoseconds.
and from MikeyB - echo $(($(date +%s%N)/1000000)) (dividing by 1000 only brings to microseconds)
You may simply use %3N to truncate the nanoseconds to the 3 most significant digits (which then are milliseconds):
$ date +%s%3N
1397392146866
This works e.g. on my Kubuntu 12.04 (Precise Pangolin).
But be aware that %N may not be implemented depending on your target system. E.g. tested on an embedded system (buildroot rootfs, compiled using a non-HF ARM cross toolchain) there was no %N:
$ date +%s%3N
1397392146%3N
(And also my (non rooted) Android tablet doesn't have %N.)