# Question about time addition by Ruby filter

**URL:** <https://discuss.elastic.co/t/question-about-time-addition-by-ruby-filter/203136>\
**Category:** Logstash\
**Created:** [October 11, 2019, 3:42am UTC](https://discuss.elastic.co/t/question-about-time-addition-by-ruby-filter/203136 "2019-10-11T03:42:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![smash](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@smash](https://discuss.elastic.co/u/smash)\
**Post date:** [October 11, 2019, 3:42am UTC](https://discuss.elastic.co/t/question-about-time-addition-by-ruby-filter/203136/1 "2019-10-11T03:42:21Z")

</div>

The following was correctly output to the "date\_time\_1" field after adding 9 hours to the date and time of "Timestamp".The following is the source

```
    ruby {
			 code => "event.set('tt',event.get('[@timestamp]').time.localtime('+09:00').strftime('%Y-%m-%d %H:%M:%S'))" 
    }

    mutate {
        add_field => {"date_time_1" => "%{[tt]}"}
	}

```

The problem is this  
it was not output correctly after adding 9 hours to the date and time of IISLog output to the log.The value of the “date\_time\_1” field is “% {[tt]}”.  
The following is the source

```
    #Input data byIISlog
    grok {
        match => ["message", "%{TIMESTAMP_ISO8601:date_time} %{GREEDYDATA:etc}"]
	}

    date {
    	match => ["date_time", "YYYY-MM-dd HH:mm:ss"]
    	timezone => "Etc/GMT"
    	target => "date_time"
	}

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

    mutate {
        add_field => {"date_time_1" => "%{[tt]}"}
	}

```

What format does the IISLog date and time calculate with the Ruby filter? Please tell me.

Supplement  
The IIS log "2019-01-01 01:23" UTC time.write  
I want to convert this to "2019-01-01 10:23" and outputing.  
Please let me know if you have any alternative means.  
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:** [October 11, 2019, 3:40pm UTC](https://discuss.elastic.co/t/question-about-time-addition-by-ruby-filter/203136/2 "2019-10-11T15:40:26Z")

</div>

Specify a different timezone in the date filter?

```
date {
    match => ["date_time", "YYYY-MM-dd HH:mm:ss"]
    timezone => "Etc/GMT+9"
    target => "date_time"
}
```

---

<div class="post-metadata">

**Author:** ![smash](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@smash](https://discuss.elastic.co/u/smash)\
**Post date:** [October 15, 2019, 1:55am UTC](https://discuss.elastic.co/t/question-about-time-addition-by-ruby-filter/203136/3 "2019-10-15T01:55:45Z")

</div>

Badger

The reply was delayed during the holidays.  
Thank you for your reply.

Even without using a Ruby script, we were able to achieve what we wanted to do with the description you taught us.

Thank you for teaching me.

---

<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:** [November 12, 2019, 1:55am UTC](https://discuss.elastic.co/t/question-about-time-addition-by-ruby-filter/203136/4 "2019-11-12T01:55:55Z")

</div>

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