# Time - script API

Time API offers helper functions to manipulate with [time type](/5.1/develop/reference/scripting/time-in-scripts.md) in StackState scripts.

## Function: `Time.currentTimeSlice()`

Returns a time slice for the current timestamp

### Examples

```
Time.currentTimeSlice().then { slice -> 
    Topology.query('environments in ("Production")')
    .at(slice)
    .components()
    .thenCollect { component -> 
       Component
       .withId(component.id)
       .at(slice)
       .get()
    } 
}
```

## Function: `Time.format(instant: Instant, pattern: String)`

Format an instant to string using the given formatting pattern

### Args

* `instant` - [an instant type representation](/5.1/develop/reference/scripting/time-in-scripts.md#type-instant).
* `pattern` - [Java date formatting pattern](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/format/DateTimeFormatter.html#patterns)

### Examples

Format an instant to ISO 8601 time

```
Time.format(1577966400000, "yyyy-MM-dd'T'HH:mm:ss'Z'")
```

## Function: `Time.epochMs(instant: Instant)`

### Args

* `instant` - [an instant type representation](/5.1/develop/reference/scripting/time-in-scripts.md#type-instant).

### Examples

Convert a string timestamp to epoch

```
Time.epochMs("2011-12-03T10:15:30Z")
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://archivedocs.stackstate.com/5.1/develop/reference/scripting/script-apis/time.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
