Unix/Linux – Displaying Timestamps in dd/mm/yyyy_hh:mm:ss:ms Format

datetimestamps

I need to display date and time in desired format in Unix/ Linux. My desired format is:
dd/mm/yyyy hh:mm:ss:ms in Unix or Linux. I got close using the following command:

echo $(date +%x_%r)

This returns:

08/20/2012_02:26:14 PM

Any suggestions?

Best Answer

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/')
Related Question