# Unix\_ms time to date

**URL:** https://discuss.elastic.co/t/unix-ms-time-to-date/220262
**Category:** Logstash
**Created:** [February 20, 2020, 8:00pm UTC](https://discuss.elastic.co/t/unix-ms-time-to-date/220262 "2020-02-20T20:00:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)
#### Post date: [February 20, 2020, 8:00pm UTC](https://discuss.elastic.co/t/unix-ms-time-to-date/220262/1 "2020-02-20T20:00:53Z")

</div>

I have date\_time = 1582225804228  
which is Thursday, February 20, 2020 1:10:04.228

when I use following filter it convert that to 2020-02-20T19:10:04.228Z ( which is UTC) time format

But I also want another field created with it which represent CST = 2020-02-20T01:10

this is my code but it didn't work

```
-- Follwoing works- output to - 2020-02-20T19:10:04.228Z (UTC)

date { match => ["date_time", "UNIX_MS","ISO8601"]
      target => "date_time"
   }

-- This do not work what ever I do. it still print time in UTC i.e 19:10
date { match => ["date_time_timezone", "UNIX_MS","ISO8601"]
      timezone => "CST6CDT"
      target => "date_time_timezone"
   }

```

How do I convert this in to -6 hour ?

---

<div class="post-metadata">

### Author: ![ITIC](https://avatars.discourse-cdn.com/v4/letter/i/90ced4/32.png) [@ITIC](https://discuss.elastic.co/u/ITIC)
#### Post date: [February 21, 2020, 7:15am UTC](https://discuss.elastic.co/t/unix-ms-time-to-date/220262/2 "2020-02-21T07:15:26Z")

</div>

Hi

To convert time to your local time you can use a `ruby{}` filter like this:

```auto
  date { match => ["date_time", "UNIX_MS","ISO8601"]
             target => "date_time"
        }

  ruby {
    code => "
      event.set('date_time_timezone', event.get('date_time').time.localtime.strftime('%Y-%m-%d %H:%M:%S'))
    "
  }

```

Adjust the time format to match your needs.

Hope this helps

---

<div class="post-metadata">

### Author: ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)
#### Post date: [February 21, 2020, 3:36pm UTC](https://discuss.elastic.co/t/unix-ms-time-to-date/220262/3 "2020-02-21T15:36:11Z")

</div>

@ITIC this is exactly what I wanted. Thank you

I just did add following after ruby. that made that time exactly same as my local time.  
and now I have two timestamp in index one is UTC one is local.  
kibana I use UTC time  
sql I use local time.

```
   date { match => ["date_time_timezone", "yyyy-MM-dd HH:mm:ss"]
      timezone => "Etc/UTC"
      target => "date_time_timezone"
   }
```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 20, 2020, 3:36pm UTC](https://discuss.elastic.co/t/unix-ms-time-to-date/220262/4 "2020-03-20T15:36:17Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
