# "Undefined method \`gsub!'" when executes a Ruby filter to change timezone

**URL:** <https://discuss.elastic.co/t/undefined-method-gsub-when-executes-a-ruby-filter-to-change-timezone/180420>\
**Category:** Logstash\
**Created:** [May 9, 2019, 5:41pm UTC](https://discuss.elastic.co/t/undefined-method-gsub-when-executes-a-ruby-filter-to-change-timezone/180420 "2019-05-09T17:41:12Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![marcogarfias](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@marcogarfias](https://discuss.elastic.co/u/marcogarfias)\
**Post date:** [May 9, 2019, 8:18pm UTC](https://discuss.elastic.co/t/undefined-method-gsub-when-executes-a-ruby-filter-to-change-timezone/180420/3 "2019-05-09T20:18:00Z")

</div>

Hi Badger,

I tried to use "timezone" in Date filter, my issue is that the input date is already in GMT and I need this value with my localtime to extract the "hour of day" and "day of week".

I mean the opposite function, I read other topics where it says the only way is using Ruby code to do that.

> [@Convert utc format to local time](https://discuss.elastic.co/t/convert-utc-format-to-local-time/164237/3):
>
> thank you. I have tried as your said. Athough no exception happens, the 'snapTime' filed still retainutc format rather than my local time zone. The filter as follows: filter{ ruby{ init =\> 'require "time"' code =\> "event.set('snapTime',Time.parse(event.get('snapTime')).localtime('+08:00'))" } } The rubydebug stdout as follows: { "snapTime" =\> 2019-01-10T02:39:12.000Z, "@version" =\> "1", "@timestamp" =\> 2019-01-15T07:22:59.390Z, "name" =\> "wangqh" } the field 'snapTime' st…

> <https://stackoverflow.com/questions/29302444/convert-timestamp-timezone-in-logstash-for-output-index-name>

Thanks for any advise

PD. I fixed the functions 'stfrtime' and I have the same error

---

_[View the full topic](https://discuss.elastic.co/t/undefined-method-gsub-when-executes-a-ruby-filter-to-change-timezone/180420)._
