---
schema_version: "1"
id: eee83398660f5619b5dd3f44a8a96f56d13a44dc532887cb6f4b6d2da6eaf028
title: duration()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/ref-jsapi/ref-jsapi-auralocalizationservice-duration.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/ref-jsapi-auralocalizationservice-duration.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: c614e191bb673578eed9b38dc6380cd2afcd37e6a54318e60746b0226529e9db
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# duration()

Returns an object representing a length of time.

## Signature

`duration (number num, String unit)`

## Parameters

**_num_:** Type: `number`. The length of time in a given unit.

**_unit_**

Type: `String`

A datetime unit. The default is 'milliseconds'. The options are 'years, 'months', 'weeks', 'days', 'hour', 'minutes', 'seconds', 'milliseconds'.

## Returns

**Type: `Object`** A duration object.

## Sample Code

```javascript
var dur = $A.localizationService.duration(2, 'days');
```

