# Extracting time from @timestamp field using Runtime

**URL:** <https://discuss.elastic.co/t/extracting-time-from-timestamp-field-using-runtime/348468>\
**Category:** Kibana\
**Tags:** runtime\
**Created:** [December 2, 2023, 7:53am UTC](https://discuss.elastic.co/t/extracting-time-from-timestamp-field-using-runtime/348468 "2023-12-02T07:53:37Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [December 2, 2023, 4:55pm UTC](https://discuss.elastic.co/t/extracting-time-from-timestamp-field-using-runtime/348468/4 "2023-12-02T16:55:18Z")

</div>

> [@Ethan777100](#):
>
> Yes `HH:mm:ss` is what im looking for

So you need to look at examples here...

> **[Using Datetime in Painless | Painless Scripting Language \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-datetime.html)**

And the API Here...

> - [java.time](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference-shared-java-time.html)
> - [java.time.chrono](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference-shared-java-time-chrono.html)
> - [java.time.format](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference-shared-java-time-format.html)
> - [java.time.temporal](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference-shared-java-time-temporal.html)
> - [java.time.zone](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference-shared-java-time-zone.html)

OK we can do that as a keyword... filtering and sorting you will need to see if that works... You will need to figure out the timezone stuff if you want to...

```auto
ZonedDateTime zdt = doc['@timestamp'].value;
String datetime = zdt.format(DateTimeFormatter.ISO_LOCAL_TIME);
emit(datetime);

```

 ![Screenshot 2023-12-02 at 8.54.19 AM](https://us1.discourse-cdn.com/elastic/original/3X/2/f/2fbf4ab83219db736ff5d3a1b87670c67105b191.png)

 ![Screenshot 2023-12-02 at 8.54.32 AM](https://us1.discourse-cdn.com/elastic/original/3X/b/6/b6c4f6a85d30160411bb6cb937aed974acba0907.png)

---

_[View the full topic](https://discuss.elastic.co/t/extracting-time-from-timestamp-field-using-runtime/348468)._
