# Convert timestamps to UTC(UNIX) from PST,IST

**URL:** https://discuss.elastic.co/t/convert-timestamps-to-utc-unix-from-pst-ist/193386
**Category:** Logstash
**Created:** [August 1, 2019, 6:18pm UTC](https://discuss.elastic.co/t/convert-timestamps-to-utc-unix-from-pst-ist/193386 "2019-08-01T18:18:36Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![naveenrt23](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@naveenrt23](https://discuss.elastic.co/u/naveenrt23)
#### Post date: [August 1, 2019, 6:18pm UTC](https://discuss.elastic.co/t/convert-timestamps-to-utc-unix-from-pst-ist/193386/1 "2019-08-01T18:18:36Z")

</div>

Hello,

How can I convert my timestamps in UNIX from different timezones such as EDT, PST/IST to UTC in Logstash filters?

---

<div class="post-metadata">

### Author: ![admlko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/admlko/32/21787_2.png) [@admlko](https://discuss.elastic.co/u/admlko)
#### Post date: [August 1, 2019, 6:21pm UTC](https://discuss.elastic.co/t/convert-timestamps-to-utc-unix-from-pst-ist/193386/2 "2019-08-01T18:21:52Z")

</div>

With date or ruby filter. If you need help, you have to show an example of what you are trying to do.

---

<div class="post-metadata">

### Author: ![naveenrt23](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@naveenrt23](https://discuss.elastic.co/u/naveenrt23)
#### Post date: [August 1, 2019, 6:54pm UTC](https://discuss.elastic.co/t/convert-timestamps-to-utc-unix-from-pst-ist/193386/3 "2019-08-01T18:54:31Z")

</div>

This block of code I use is to convert timestamp to UNIX and

`event.set('timestamp', event.get('timestamp_object').to_i * 1000)`

we use this block to convert the timestamp to UTC  
date {  
timezone =\> "UTC"  
match =\> ["timestamp\_local" , "yyyyMMddHHmmss"]  
target =\> "timestamp\_object"  
}

Ex:

```
 "timestamp_local" => "20190730112353"
"timestamp_object" => 2019-07-30T11:23:53.000Z"
 "timestamp" => 1564485833000"

```

I can see the code is converting into a different format rather than a timezone

---

<div class="post-metadata">

### Author: ![admlko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/admlko/32/21787_2.png) [@admlko](https://discuss.elastic.co/u/admlko)
#### Post date: [August 1, 2019, 7:41pm UTC](https://discuss.elastic.co/t/convert-timestamps-to-utc-unix-from-pst-ist/193386/4 "2019-08-01T19:41:37Z")

</div>

Huh?

So first you have a “timestamp\_object” field, which contains timestamp in Unix timestamp format. You multiply it by 1000 to get it into milliseconds and store the result into “timestamp” field.  
Then from somewhere comes the timestamp\_local field, which uses “yyyyMMddHHmmss” format, you parse the timestamp from that field and overwrite “timestamp\_object” field with the result.

I’m not sure what is the issue, what do you expect to be different?

---

<div class="post-metadata">

### Author: ![naveenrt23](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@naveenrt23](https://discuss.elastic.co/u/naveenrt23)
#### Post date: [August 1, 2019, 8:00pm UTC](https://discuss.elastic.co/t/convert-timestamps-to-utc-unix-from-pst-ist/193386/5 "2019-08-01T20:00:46Z")

</div>

I apologize if I didn't put the question correctly. my input is "timestamp\_local" which needs to be converted to UTC UNIX format.  
so for that, we initially tried to convert it to UTC which is the below code  
date {  
timezone =\> "UTC"  
match =\> ["timestamp\_local" , "yyyyMMddHHmmss"]  
target =\> "timestamp\_object"  
}

Now, I am expecting the timestamp\_object to be in UTC format but I don't see the timestamp\_object in UTC and then comes the conversion to UNIX in ms.

`event.set('timestamp', event.get('timestamp_object').to_i * 1000)`

which is working fine..so my only issue is the block which needs to convert to UTC timezone is not actually converting it..It looks like it's only changing the format not the timezone

---

<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: [August 1, 2019, 8:06pm UTC](https://discuss.elastic.co/t/convert-timestamps-to-utc-unix-from-pst-ist/193386/6 "2019-08-01T20:06:03Z")

</div>

A date filter _always_ converts to UTC. The timezone option is used to tell what timezone it is converting _from_, i.e. the name of your local timezone. Note that PST and IST are ambiguous. Use whatever zone name the Joda [documentation](http://joda-time.sourceforge.net/timezones.html) lists for the same offset.

---

<div class="post-metadata">

### Author: ![naveenrt23](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@naveenrt23](https://discuss.elastic.co/u/naveenrt23)
#### Post date: [August 1, 2019, 8:17pm UTC](https://discuss.elastic.co/t/convert-timestamps-to-utc-unix-from-pst-ist/193386/7 "2019-08-01T20:17:55Z")

</div>

Oh cool..so when i specify timezone as UTC ,all i am doing is specifying that the server timestamp is in UTC timezone and not the timezone that i need it to be converted to? So If i specify timezone as Etc/GMT+4 for example...it is going to convert timestamp "timestamp\_local" to Etc/GMT+4 ?

---

<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: [August 1, 2019, 8:22pm UTC](https://discuss.elastic.co/t/convert-timestamps-to-utc-unix-from-pst-ist/193386/8 "2019-08-01T20:22:27Z")

</div>

If you timestamp is in Etc/GMT+4 then you should specify that as the value of the timezone option. As I said, it will get converted to UTC.

---

<div class="post-metadata">

### Author: ![naveenrt23](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@naveenrt23](https://discuss.elastic.co/u/naveenrt23)
#### Post date: [August 1, 2019, 8:25pm UTC](https://discuss.elastic.co/t/convert-timestamps-to-utc-unix-from-pst-ist/193386/9 "2019-08-01T20:25:17Z")

</div>

Cool. Thank You !

---

<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: [August 29, 2019, 8:34pm UTC](https://discuss.elastic.co/t/convert-timestamps-to-utc-unix-from-pst-ist/193386/10 "2019-08-29T20:34:09Z")

</div>

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