# Change logstash default @timestamp format

**URL:** <https://discuss.elastic.co/t/change-logstash-default-timestamp-format/322857>\
**Category:** Logstash\
**Created:** [January 10, 2023, 10:12pm UTC](https://discuss.elastic.co/t/change-logstash-default-timestamp-format/322857 "2023-01-10T22:12:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![markedperf](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@markedperf](https://discuss.elastic.co/u/markedperf)\
**Post date:** [January 10, 2023, 10:12pm UTC](https://discuss.elastic.co/t/change-logstash-default-timestamp-format/322857/1 "2023-01-10T22:12:00Z")

</div>

I am looking to change the default @timestamp format from nano seconds ("@timestamp" : "2023-01-07T17:26:16.969990782Z") to just milliseconds ("@timestamp" : "2023-01-07T17:26:16.969" or "@timestamp" : "2023-01-07T17:26:16.969Z"). I have seen a lot of examples with a conf file with date filter, gsub, etc.. but nothing seems to work, it always produces "@timestamp" : "2023-01-07T17:26:16.969990782Z" format. Is there another place I should be looking or a way in the conf file that works? 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:** [January 11, 2023, 1:00am UTC](https://discuss.elastic.co/t/change-logstash-default-timestamp-format/322857/2 "2023-01-11T01:00:33Z")

</div>

You can do it using

```
    ruby { code => 'event.set("[@metadata][ts]", event.get("@timestamp").to_s.sub(/(\d{3})\d{6}/, "\\1"))' }
    date { match => ["[@metadata][ts]", ISO8601 ] }

```

That does not round the milliseconds, it just drops the last six digits, but that is what you asked for 🙂

---

<div class="post-metadata">

**Author:** ![markedperf](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@markedperf](https://discuss.elastic.co/u/markedperf)\
**Post date:** [January 11, 2023, 1:41pm UTC](https://discuss.elastic.co/t/change-logstash-default-timestamp-format/322857/3 "2023-01-11T13:41:29Z")

</div>

That worked. 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:** [February 8, 2023, 1:41pm UTC](https://discuss.elastic.co/t/change-logstash-default-timestamp-format/322857/4 "2023-02-08T13:41:36Z")

</div>

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