Getting current date and time with milliseconds precision

Maxim Dounin mdounin at
Wed Nov 16 18:07:50 UTC 2022


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 ($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 (

Hope this helps.

Maxim Dounin

More information about the nginx mailing list