# Convert UTC time to specified timezone

**URL:** <https://discuss.elastic.co/t/convert-utc-time-to-specified-timezone/78928>\
**Category:** Logstash\
**Created:** [March 16, 2017, 8:09pm UTC](https://discuss.elastic.co/t/convert-utc-time-to-specified-timezone/78928 "2017-03-16T20:09:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![matohl](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@matohl](https://discuss.elastic.co/u/matohl)\
**Post date:** [March 16, 2017, 8:09pm UTC](https://discuss.elastic.co/t/convert-utc-time-to-specified-timezone/78928/1 "2017-03-16T20:09:00Z")

</div>

Hi,

I have a log with events from different timezones, where the timestamps are all UTC. I also have the names of the timezones, e.g. "Europe/Madrid". I want to check if the event occurred during office hours in the local time zone, i.e. first convert the timestamp to the local timezone and then check if the converted time is between , for example, 9 and 17. Assuming 7-day work-week. I am looking for something like this:

```
ruby {
  code =>
"
  localTime = event.get('timestamp').time.convert( event.get('timeZone') )
  if localTime.hour > 8 && localTime.hour < 18
    event.set('duringOfficeHours', true)
  end
"
}

```

where the convert-function is unknown to me, i.e. what I am looking for. I have seen a reference to a DateTime.in\_time\_zone method in some forums, but it does not seem to exist in my logstash 5.2.2.

Is this possible to accomplish? Thanks in advance!

---

<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:** [April 13, 2017, 8:09pm UTC](https://discuss.elastic.co/t/convert-utc-time-to-specified-timezone/78928/2 "2017-04-13T20:09:31Z")

</div>

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