# Transform datetime to string

**URL:** <https://discuss.elastic.co/t/transform-datetime-to-string/148822>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [September 17, 2018, 11:36am UTC](https://discuss.elastic.co/t/transform-datetime-to-string/148822 "2018-09-17T11:36:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakn](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@jakn](https://discuss.elastic.co/u/jakn)\
**Post date:** [September 17, 2018, 11:36am UTC](https://discuss.elastic.co/t/transform-datetime-to-string/148822/1 "2018-09-17T11:36:30Z")

</div>

I use the following transform in a watcher

```
"transform": {
    "script": {
      "source": "return ['time_triggered': Instant.ofEpochMilli(ctx.trigger.triggered_time.getMillis()).atZone(ZoneId.of('Europe/Copenhagen'))]",
      "lang": "painless"
    }
  }

```

Which outputs a timestamp like  
`2018-08-16T10:13:58.698+02:00[Europe/Copenhagen]`

Instead I would like to be able to insert this output in an email action.  
`2018-08-16 10:13:58`

How do I get that string?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 17, 2018, 12:45pm UTC](https://discuss.elastic.co/t/transform-datetime-to-string/148822/2 "2018-09-17T12:45:03Z")

</div>

try using a date formatter (new lines for the sake of readability)

```auto
return [ 'time_triggered': Instant.ofEpochMilli(ctx.trigger.triggered_time.getMillis())
.atZone(ZoneId.of('Europe/Copenhagen'))
.format(DateTimeFormatter.ofPattern('YYYY-MM-dd HH:mm:ss')) ]

```

---

<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:** [October 15, 2018, 12:45pm UTC](https://discuss.elastic.co/t/transform-datetime-to-string/148822/3 "2018-10-15T12:45:06Z")

</div>

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