Print current time (with milliseconds)

I want this command in windows with cygwin installed, so any Linux command will work for me.

1

3 Answers

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

0

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
4

Here is the command where you can print the json-like ISO format current time:

date +%FT%T.%3N

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like