How do I get the current unix time in milliseconds (i.e number of milliseconds since Unix epoch Jan 1 1970) ?
Thanks
Richard.
|
feedback
|
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 - | |||||||||||||||
feedback
|
|
Just throwing this out there, but I think the correct formula with the division would be:
| ||||
|
feedback
|
|
Here is how to get time in milliseconds without performing division. Maybe it's faster...
| |||
feedback
|
|
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. | |||
|
feedback
|
|
My solution is not the best but worked for me.
I just needed to convert a date like 2012-05-05 to milliseconds. | ||||
|
feedback
|