# Changing Time Format

**URL:** https://discuss.elastic.co/t/changing-time-format/278115
**Category:** Logstash
**Created:** [July 7, 2021, 9:42pm UTC](https://discuss.elastic.co/t/changing-time-format/278115 "2021-07-07T21:42:12Z")
**Posts on this page:** 1
**Showing post:** 2

<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: [July 7, 2021, 9:55pm UTC](https://discuss.elastic.co/t/changing-time-format/278115/2 "2021-07-07T21:55:50Z")

</div>

If you want those fields to be strings in a particular format then I suggest using a date filter to parse them into LogStash::Timestamp objects, then ruby and strftime to set the format you want. Something like this

```
date {
    match => ["deviceCustomDate1", "M/d/YYYY h:mm:ss a"]
    target => "[@metadata][deviceCustomDate1]"
}
ruby {
    code => '
        t = Time.at(event.get("[@metadata][deviceCustomDate1]").to_f)
        event.set("deviceCustomDate1", t.strftime("%b %d %Y %H:%M:%S"))
    '
}

```

Not sure if you want to replace %d with %-d or %e.

---

_[View the full topic](https://discuss.elastic.co/t/changing-time-format/278115)._
