# Convert datetime to another timezone in logstash

**URL:** <https://discuss.elastic.co/t/convert-datetime-to-another-timezone-in-logstash/336214>\
**Category:** Logstash\
**Created:** [June 16, 2023, 11:50am UTC](https://discuss.elastic.co/t/convert-datetime-to-another-timezone-in-logstash/336214 "2023-06-16T11:50:11Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [June 16, 2023, 8:06pm UTC](https://discuss.elastic.co/t/convert-datetime-to-another-timezone-in-logstash/336214/9 "2023-06-16T20:06:33Z")

</div>

You can do it in ruby.

```
    mutate { add_field => { "rt" => "Jun 16 2023 11:24:40 GMT" } }
    date { match => ["rt", "MMM dd YYYY HH:mm:ss ZZZ"] }

    ruby {
        code => '
            t = event.get("[@timestamp]").to_f
            t = Time.at(t, in: "+08:00")
            event.set("localtime", t.strftime("%b %d %Y %H:%M:%S MYT"))
        '
    }

```

will produce

```
 "localtime" => "Jun 16 2023 19:24:40 MYT",
"@timestamp" => 2023-06-16T11:24:40.000Z,

```

I don't think core Ruby has enough timezone support to avoid specifying both the offset and the name of MYT.

---

_[View the full topic](https://discuss.elastic.co/t/convert-datetime-to-another-timezone-in-logstash/336214)._
