# Convert UTC datetime to specified timezone

**URL:** <https://discuss.elastic.co/t/convert-utc-datetime-to-specified-timezone/235970>\
**Category:** Logstash\
**Created:** [June 5, 2020, 2:53pm UTC](https://discuss.elastic.co/t/convert-utc-datetime-to-specified-timezone/235970 "2020-06-05T14:53:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![not\_found](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@not\_found](https://discuss.elastic.co/u/not_found)\
**Post date:** [June 5, 2020, 2:53pm UTC](https://discuss.elastic.co/t/convert-utc-datetime-to-specified-timezone/235970/1 "2020-06-05T14:53:18Z")

</div>

Hello,

I have this following date : 2020-02-05 15:31:46 UTC  
I would like to convert it with ruby into Europe/Brussels.

I tried :

```auto
puts Time.parse(mydate2) // 2020-02-05 15:31:46 UTC
puts Time.parse(mydate2).zone // UTC 
puts Time.parse(mydate2).in_time_zone('Europe/Brussels') // Ruby exception occurred: undefined method `in_time_zone' for 2020-02-05 15:31:46 UTC:Time

```

How can I convert an event.date UTC to datetime on Europe/Brussels Timezone ?

Thanks

---

<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 5, 2020, 3:07pm UTC](https://discuss.elastic.co/t/convert-utc-datetime-to-specified-timezone/235970/2 "2020-06-05T15:07:10Z")

</div>

in\_time\_zone is a rails thing, not present in basic Ruby. But you do not need a ruby filter to do this, you can do it using a date filter. If you want to move from UTC to Europe/Brussels, which is Etc/GMT-1, then tell the date filter it is actually Etc/GMT+1, or Atlantic/Azores.

```
input { generator { count => 1 lines => [''] } }
filter {
    mutate { add_field => { "timestamp" => "2020-02-05 15:31:46 UTC" } }
    mutate { gsub => ["timestamp", " UTC", ""] }
    date { match => ["timestamp", "YYYY-MM-dd HH:mm:ss"] timezone => "Atlantic/Azores" target => "timestamp2" }
    mutate { convert => { "timestamp2" => "string" } }
    mutate { gsub => ["timestamp2", "Z$", ""] }
}
output { stdout { codec => rubydebug { metadata => false } } }

```

will produce

```
 "timestamp" => "2020-02-05 15:31:46",
"timestamp2" => "2020-02-05T16:31:46.000",
```

---

<div class="post-metadata">

**Author:** ![not\_found](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@not\_found](https://discuss.elastic.co/u/not_found)\
**Post date:** [June 8, 2020, 7:08am UTC](https://discuss.elastic.co/t/convert-utc-datetime-to-specified-timezone/235970/3 "2020-06-08T07:08:51Z")

</div>

Hey Badger,

I will give a try this morning !

Thanks for your time, didn't know about the date filter plugin.

---

<div class="post-metadata">

**Author:** ![not\_found](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@not\_found](https://discuss.elastic.co/u/not_found)\
**Post date:** [June 8, 2020, 7:47am UTC](https://discuss.elastic.co/t/convert-utc-datetime-to-specified-timezone/235970/4 "2020-06-08T07:47:59Z")

</div>

Seems not working.

```
mutate { add_field => { "timestamp" => "2020-06-08 07:31:46 UTC" } }
mutate { gsub => ["timestamp", " UTC", ""] }
date { match => ["timestamp", "YYYY-MM-dd HH:mm:ss"] timezone => "Europe/Brussels" target => "timestamp2" }
mutate { convert => { "timestamp2" => "string" } }
mutate { gsub => ["timestamp2", "Z$", ""] }

```

Result :

```
{
    "timestamp" => "2020-06-08 07:31:46",
    "timestamp2" => "2020-06-08T05:31:46.000"
}

```

Timestamps2 should have been 09:31:46.  
I have the feeling that "timezone" property is the timezone of the given match.

The date plugin filter seems to convert to UTC in anyway.

---

<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 8, 2020, 2:09pm UTC](https://discuss.elastic.co/t/convert-utc-datetime-to-specified-timezone/235970/5 "2020-06-08T14:09:58Z")

</div>

That's why you have to tell it the timezone of the log file has the opposite sign to the adjustment you want to apply. Atlantic/Azores, not Europe/Brussels.

---

<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:** [July 6, 2020, 2:10pm UTC](https://discuss.elastic.co/t/convert-utc-datetime-to-specified-timezone/235970/6 "2020-07-06T14:10:02Z")

</div>

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