# Wrong timestamp, when trying to convert local time to UTC

**URL:** https://discuss.elastic.co/t/wrong-timestamp-when-trying-to-convert-local-time-to-utc/239111
**Category:** Logstash
**Created:** [June 29, 2020, 12:37pm UTC](https://discuss.elastic.co/t/wrong-timestamp-when-trying-to-convert-local-time-to-utc/239111 "2020-06-29T12:37:26Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![asmerb](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@asmerb](https://discuss.elastic.co/u/asmerb)
#### Post date: [June 29, 2020, 12:37pm UTC](https://discuss.elastic.co/t/wrong-timestamp-when-trying-to-convert-local-time-to-utc/239111/1 "2020-06-29T12:37:26Z")

</div>

Hi everyone,

I am using LogStash and ElasticSearch 6.3.1

Currently having an issue where my @timestamp is being shifted by two hours.

I am picking up records in logstash that comes from filebeat, the timestamp here is being recorded in local time (Europe/Vienna which is UTC +2).

I understand logstash records time in UTC and if I am not misunderstanding for the reading and research, this is where the 2 hours get shifted. So I am trying to tell logstash that the time is in local time Vienna (UTC +2) so logstash can store the time correctly.

I am ussing the folllowing configuration and still getting the 2 shifted hours, Hoping someone can give a hand to understand what the problem can be.

Using a grok filter to match the message as follow:

```auto
grok {
match => { "message" =>
"%{INT:timestamp},%{DATA:transactionId},%{WORD:eventType},%{INT:subscriberId},%{DATA:action},%{DATA:accountId},%{DATA:accType},%{DATA:socName},%{DATA:subsoc},%{DATA:socList},%{GREEDYDATA:subTariff},%{GREEDYDATA:socDate},%{DATA:errorCode},%{GREEDYDATA:errorMessage},%{GREEDYDATA:status},%{DATA:subscriberRole},%{DATA:accTariff},%{DATA:cycleStartDay},%{DATA:accEmail},%{DATA:SOCDealerCode}"
}

```

Then a ruby filter that takes the timestamp an create a firl CREATED\_ON\_DATE that contains the timestamp as UNIX

```auto
 ruby {
 init => "require 'date'"
 code => "event.set('CREATED_ON_DATE',DateTime.parse(event.get('timestamp')).to_time.to_i)"
}

```

and finally a date filter to match CREATE\_ON\_DATE to @timestamp:

```auto
date {
match => ["CREATED_ON_DATE", "UNIX"]
timezone => "Europe/Vienna"
target => "@timestamp"
}

```

![timestamp](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e7d0d83d773d7fe59f2d2ce6b9b231170796fed.png)

See the diferent on the timestamp (+2 hours)

Thanks in advance for the support

---

<div class="post-metadata">

### Author: ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)
#### Post date: [June 29, 2020, 1:22pm UTC](https://discuss.elastic.co/t/wrong-timestamp-when-trying-to-convert-local-time-to-utc/239111/2 "2020-06-29T13:22:04Z")

</div>

I don't think that your `timezone` setting will do anything if your date is already a unix timestamp and not a formatted string anyway. The problem is that your Ruby code already interprets your date as UTC (as you can see if you convert the integer value that it has created). Is there a reason for that intermediate step? Couldn't you parse it with a date filter with `yyyyMMddHHmmss` (and with the timezone setting because then this should take effect)?

---

<div class="post-metadata">

### Author: ![asmerb](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@asmerb](https://discuss.elastic.co/u/asmerb)
#### Post date: [June 29, 2020, 2:21pm UTC](https://discuss.elastic.co/t/wrong-timestamp-when-trying-to-convert-local-time-to-utc/239111/3 "2020-06-29T14:21:09Z")

</div>

Hi Jenni, Thanks for your quick response, I see the problem now, and indeed you are 100% correct, I have done what you suggested and it is working fine, so I will go with that aproach , thanks again for your support.

```auto
 date {
                     match => ["timestamp", "yyyyMMddHHmmss"]
                     timezone => "Europe/Vienna"
                     target => "@timestamp"
                 }

```

---

<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 27, 2020, 2:21pm UTC](https://discuss.elastic.co/t/wrong-timestamp-when-trying-to-convert-local-time-to-utc/239111/4 "2020-07-27T14:21:20Z")

</div>

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