# Convert $msec to sec

**URL:** <https://www.ruby-forum.com/t/convert-msec-to-sec/244395>\
**Category:** NGINX\
**Created:** [April 3, 2016, 8:01am UTC](https://www.ruby-forum.com/t/convert-msec-to-sec/244395 "2016-04-03T08:01:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [April 3, 2016, 8:01am UTC](https://www.ruby-forum.com/t/convert-msec-to-sec/244395/1 "2016-04-03T08:01:36Z")

</div>

I need to log the seconds since epoch (without the millisecond  
resolution)  
in the access\_log file

is there is a way to convert the $msec to seconds or drop the  
exponential  
part of the time . Probably using the map function?.

Thank you,

---

<div class="post-metadata">

**Author:** ![Anoop\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@Anoop\_A](https://www.ruby-forum.com/u/Anoop_A)\
**Post date:** [April 3, 2016, 2:40pm UTC](https://www.ruby-forum.com/t/convert-msec-to-sec/244395/2 "2016-04-03T14:40:34Z")

</div>

On Sunday 03 April 2016 11:31:08 Anoop A. wrote:

> I need to log the seconds since epoch (without the millisecond resolution)  
> in the access\_log file
> 
> is there is a way to convert the $msec to seconds or drop the exponential  
> part of the time . Probably using the map function?.

It’s easy with the map directive:

```
map $msec $sec {
    ~^(?P<_sec>.+)\. $_sec;
}

```

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Anoop\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@Anoop\_A](https://www.ruby-forum.com/u/Anoop_A)\
**Post date:** [April 3, 2016, 5:11pm UTC](https://www.ruby-forum.com/t/convert-msec-to-sec/244395/3 "2016-04-03T17:11:18Z")

</div>

Thanks Valentin. That works.

Can you explain

---

<div class="post-metadata">

**Author:** ![Anoop\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@Anoop\_A](https://www.ruby-forum.com/u/Anoop_A)\
**Post date:** [April 3, 2016, 10:25pm UTC](https://www.ruby-forum.com/t/convert-msec-to-sec/244395/4 "2016-04-03T22:25:35Z")

</div>

On Sunday 03 April 2016 20:40:33 Anoop A. wrote:

> Thanks Valentin. That works.
> 
> Can you explain

This is simple named subpattern:

> **[pcrepattern specification](https://www.pcre.org/original/doc/html/pcrepattern.html)**

used in the map directive:

> **[Module ngx\_http\_map\_module](http://nginx.org/en/docs/http/ngx_http_map_module.html#map)**
>
> The ngx\_http\_map\_module module creates variables whose values depend on values of other variables.

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Anoop\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@Anoop\_A](https://www.ruby-forum.com/u/Anoop_A)\
**Post date:** [April 3, 2016, 5:12pm UTC](https://www.ruby-forum.com/t/convert-msec-to-sec/244395/5 "2016-04-03T17:12:28Z")

</div>

On 4/3/2016 8:10 AM, Anoop A. wrote:

> Thanks Valentin. That works.
> 
> Can you explain  
> see [Module ngx\_http\_map\_module](http://nginx.org/en/docs/http/ngx_http_map_module.html)
