# @timestamp to ISO (Europe/Madrid)

**URL:** <https://discuss.elastic.co/t/timestamp-to-iso-europe-madrid/307056>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [June 13, 2022, 5:03pm UTC](https://discuss.elastic.co/t/timestamp-to-iso-europe-madrid/307056 "2022-06-13T17:03:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Fernandez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonathan_fernandez/32/102934_2.png) [@Jonathan\_Fernandez](https://discuss.elastic.co/u/Jonathan_Fernandez)\
**Post date:** [June 13, 2022, 5:03pm UTC](https://discuss.elastic.co/t/timestamp-to-iso-europe-madrid/307056/1 "2022-06-13T17:03:23Z")

</div>

Hi everyone!

So basically I have to parse my UTC timestamp in a set of Elasticsearch Watchers to ISO (Europe/Madrid).

**IMPORTANT:** I cannot use Logstash, quite unsure that use an Ingest Node for this would be permitted, so I may need an Elasticsearch Watcher code solution.

The main idea is to code it in a dynamic way, so I do not have to change the code every summer/winter-time. At this point anything that could be done at Watcher (JSON code) level would work for me.

Currently I'm using a transform as follows:  
` "transform": { "script": { "source": """def theDate = ctx.trigger.triggered_time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss Z")); return ['date': theDate, 'aggregations': ctx.payload.aggregations];""", "lang": "painless" } }`

This is just a temporary patch, and I may need to display the local time directly.

Could you please give me a hand?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![Jonathan\_Fernandez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonathan_fernandez/32/102934_2.png) [@Jonathan\_Fernandez](https://discuss.elastic.co/u/Jonathan_Fernandez)\
**Post date:** [June 16, 2022, 3:55pm UTC](https://discuss.elastic.co/t/timestamp-to-iso-europe-madrid/307056/2 "2022-06-16T15:55:41Z")

</div>

I solve it through the following code:

```auto
  "transform": {
    "script": {
      "source": """def dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z").withZone(ZoneId.of(ctx.metadata.timezone));
                   def theDate = ctx.trigger.triggered_time.format(dtf); 
                   return ['date': theDate, 'aggregations': ctx.payload.aggregations];""",
      "lang": "painless"
    }
  }

```

---

<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 14, 2022, 3:55pm UTC](https://discuss.elastic.co/t/timestamp-to-iso-europe-madrid/307056/3 "2022-07-14T15:55:48Z")

</div>

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