---
title: time.runits
summary: null
url: >-
  https://www.fastly.com/documentation/reference/vcl/functions/date-and-time/time-runits
---

```
STRING time.runits(STRING unit, RTIME rtime)
```

**Available in:** all subroutines

Returns a string representation of the given RTIME typed time value expressed
to the resolution specified by the unit.

Formatting to a particular resolution is done in terms of a given number of decimal places.
The `unit` parameter is used as short-hand to denote this number,
and for this reason only units which divide exactly into multiples of 1000 are allowed.

This is unlike suffixes for RTIME literals, which do not need to be multiples of 1000.
The `RTIME` suffixes `m`, `h`, `d`, `w`, `y` are not multiples of 10 and so would not make sense here.
`time.runits` also allows `ns`, which is not a valid suffix for RTIME.

## Parameters

- `unit` - A string of one of the four possible unit values: `s`, `ms`, `us`, `ns`.
- `rtime` - A time value parameter of type RTIME.

## Return Value

The return value will be of type STRING, being the text based representation of
the given time value formatted according to the unit type as specified by the
following criteria:

| Unit | Description                                                         |
| ---: | :------------------------------------------------------------------ |
|  `s` | Whole seconds only with no decimal point                            |
| `ms` | Whole seconds followed by a decimal point with three decimal places |
| `us` | Whole seconds followed by a decimal point with six decimal places   |
| `ns` | Whole seconds followed by a decimal point with nine decimal places  |

## Errors

If the `unit` argument is not a valid unit string,
then `fastly.error` will be set to `EINVAL`.

## Example

```vcl
set beresp.http.beresp-ttl-in-ms = time.runits("ms", beresp-ttl);
```
