<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Duration/UnitsFormatStyle/ZeroValueUnitsDisplayStrategy",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s8DurationV10FoundationE16UnitsFormatStyleV09ZeroValueC15DisplayStrategyV"
  },
  "title" : "Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy"
}
-->

# Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy

A strategy that determines how to format a unit whose value is zero.

```
struct ZeroValueUnitsDisplayStrategy
```

## Overview

When using a [`Duration.UnitsFormatStyle`](/documentation/Swift/Duration/UnitsFormatStyle), specifying a `ZeroValueUnitsDisplayStrategy` enables you to decide whether show a unit whose value is zero.

The following example creates a duration of 25 seconds, then formats it with two different styles. The first style uses the [`hide`](/documentation/Swift/Duration/UnitsFormatStyle/ZeroValueUnitsDisplayStrategy/hide) display strategy, which omits the hours and minutes, since their value is `0`. The second uses [`show(length:)`](/documentation/Swift/Duration/UnitsFormatStyle/ZeroValueUnitsDisplayStrategy/show(length:)) to create two-digit representations of the hour and minute fields.

```
let duration = Duration.seconds(25)
let hide = duration.formatted(
    .units(allowed: [.hours, .minutes, .seconds],
           width: .abbreviated,
           zeroValueUnits:.hide)) // 25 sec
let showTwo = duration.formatted(
    .units(allowed: [.hours, .minutes, .seconds],
           width: .abbreviated,
           zeroValueUnits:.show(length: 2))) // 00 hr, 00 min, 25 sec
```

## Topics

### Using common strategies

[`static var hide: Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy`](/documentation/Swift/Duration/UnitsFormatStyle/ZeroValueUnitsDisplayStrategy/hide)

A display strategy that hides leading fields whose value is zero.

[`static func show(length: Int) -> Duration.UnitsFormatStyle.ZeroValueUnitsDisplayStrategy`](/documentation/Swift/Duration/UnitsFormatStyle/ZeroValueUnitsDisplayStrategy/show(length:))

Returns display strategy that shows leading fields whose value is zero, with a given number of digits.

### Encoding and decoding

### Hashing

### Comparing fractional part display strategies

## Relationships

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`Sendable`](/documentation/Swift/Sendable)

[`Hashable`](/documentation/Swift/Hashable)

[`Encodable`](/documentation/Swift/Encodable)

[`Decodable`](/documentation/Swift/Decodable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)