Display time stamp in dd/mm/yyyy_hh:mm:ss:ms in Unix or Linux
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/')
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
man date
date +"%d/%m/%Y_%H:%M:%S:%N"
More useful reading:
How to format date for display or to use in a shell script