# Convert @timestamp to epoch

**URL:** https://discuss.elastic.co/t/convert-timestamp-to-epoch/64522
**Category:** Logstash
**Created:** [November 1, 2016, 7:55am UTC](https://discuss.elastic.co/t/convert-timestamp-to-epoch/64522 "2016-11-01T07:55:02Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![jsvd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsvd/32/6203_2.png) [@jsvd](https://discuss.elastic.co/u/jsvd)
#### Post date: [November 2, 2016, 10:28am UTC](https://discuss.elastic.co/t/convert-timestamp-to-epoch/64522/2 "2016-11-02T10:28:28Z")

</div>

you can use the ruby filter for this:

```auto
input { generator { count => 1 } }
filter {
  # for logstash 5.x
  ruby { code => "event.set('epoc', event.get('@timestamp').to_i)" }
  # for logstash 2.x
  # ruby { code => "event['epoc'] = event['@timestamp'].to_i" }
}
output { stdout { codec => rubydebug } }

```

```auto
{
          "epoc" => 1478082411,
      "sequence" => 0,
    "@timestamp" => 2016-11-02T10:26:51.303Z,
      "@version" => "1",
          "host" => "Joaos-MBP-5.lan",
       "message" => "Hello world!"
}

```

---

_[View the full topic](https://discuss.elastic.co/t/convert-timestamp-to-epoch/64522)._
