Print current time (with milliseconds)
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Popsicle Puzzles
--
Chapters
00:00 Print Current Time (With Milliseconds)
00:13 Accepted Answer Score 17
00:30 Answer 2 Score 44
01:18 Answer 3 Score 2
01:30 Answer 4 Score 1
01:42 Thank you
--
Full question
https://superuser.com/questions/674464/p...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#bash #cygwin #time
#avk47
ANSWER 1
Score 44
If you want to get milliseconds instead of nanoseconds, you may simply use %3N
to truncate the nanoseconds to the 3 most significant digits:
$ date +"%Y-%m-%d %H:%M:%S,%3N"
2014-01-08 16:00:12,746
or
$ date +"%F %T,%3N"
2014-01-08 16:00:12,746
testet with »GNU bash, Version 4.2.25(1)-release (i686-pc-linux-gnu)«
Also tested successfully in my cygwin installation.
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
:
date +"%F %T,%N"
2014-01-08 16:44:47,%N
ACCEPTED ANSWER
Score 17
date +%H:%M:%S:%N
will give you the current time with nano seconds, you could then chop off however many digits or rearrange the time to how you wish to have it.
date --help
can give you some other configuration options
ANSWER 3
Score 2
Here is the command where you can print the json-like ISO format current time:
date +%FT%T.%3N
ANSWER 4
Score 1
To be ISO complete I would use either:
date +%FT%T.%3N%z
for lcal time, or:
date -u +%FT%T.%3NZ
for UTC.