How do I get the current Unix time in milliseconds (i.e number of milliseconds since Unix epoch January 1 1970)?
This:
will return the number of seconds since the epoch. This:
returns the seconds and current nanoseconds. So:
will give you the number of milliseconds since the epoch - current seconds plus the left three of the nanoseconds. and from MikeyB - |
|||||||||||||||||||
|
|
Unfortunately I only seem to be able to add new answers, not comment, but I think it's worth noting that the man asked for Unix, not Linux, and the current top answer (date +%s%N) doesn't work on my AIX system. |
|||||
|
|
Just throwing this out there, but I think the correct formula with the division would be:
|
||||
|
|
|
|
|||
|
|
|
My solution is not the best but worked for me.
I just needed to convert a date like 2012-05-05 to milliseconds. |
||||
|
|
|
If you are looking for a way to display the length of time your script ran, the following will provide a (not completely accurate) result: As near the beginning of your script as you can, enter the following
This'll give you a starting value of something like 1361802943996000000 At the end of your script, use the following
which will display something like
Notes: (1*10^09) can be replaced with 1000000000 if you wish
I only tested this on Win7/MinGW... I don't have a proper *nix box to hand. |
||||
|
|
|
Here is how to get time in milliseconds without performing division. Maybe it's faster...
|
|||
|
protected by MadHatter Feb 25 at 14:49
This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.