Getting current date and time with milliseconds precision

L
  • 16 Nov '22
Hello, 
I'm trying to get the current time and date with milliseconds precision. I'm
using lua with nginx/openresty. Can someone help?

Many thanks!

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,295777,295777#msg-295777
S
  • 16 Nov '22
Hi,

On Wed, Nov 16, 2022 at 09:58:23AM -0500, libresco_27 wrote:
> Hello, 
> I'm trying to get the current time and date with milliseconds precision. I'm
> using lua with nginx/openresty. Can someone help?

lua module is the third-party product, created by another team.
Follow that, I'd recommend to use OpenResty maillist for such questions,
https://openresty.org/en/community.html

Thank you.

-- 
Sergey A. Osokin
M
  • 16 Nov '22
Hello!

On Wed, Nov 16, 2022 at 09:58:23AM -0500, libresco_27 wrote:

> Hello, 
> I'm trying to get the current time and date with milliseconds precision. I'm
> using lua with nginx/openresty. Can someone help?

In general, nginx can provide time with millisecond resolution.  
For example, see the $msec variable (http://nginx.org/r/$msec).

Note though that precision is not the same thing as resolution.  
Since nginx updates time only at the start of an event loop 
iteration, and various operations, such as disk access, might take 
significant time, likely precision will be worse than 1 
millisecond.  Further, precision might be much worse if you've 
configured nginx to update time only once in a while by using the 
timer_resolution directive (http://nginx.org/r/timer_resolution).

Hope this helps.

-- 
Maxim Dounin
http://mdounin.ru/