<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 8.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Calendar/date(bySettingHour:minute:second:of:matchingPolicy:repeatedTimePolicy:direction:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation8CalendarV4date13bySettingHour6minute6second2of14matchingPolicy012repeatedTimeK09directionAA4DateVSgSi_S2iAmC08MatchingK0OAC08RepeatedmK0OAC15SearchDirectionOtF"
  },
  "title" : "date(bySettingHour:minute:second:of:matchingPolicy:repeatedTimePolicy:direction:)"
}
-->

# date(bySettingHour:minute:second:of:matchingPolicy:repeatedTimePolicy:direction:)

Returns a new `Date` representing the date calculated by setting hour, minute, and second to a given time on a specified `Date`.

```
func date(bySettingHour hour: Int, minute: Int, second: Int, of date: Date, matchingPolicy: Calendar.MatchingPolicy = .nextTime, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, direction: Calendar.SearchDirection = .forward) -> Date?
```

## Parameters

`hour`

A specified hour.

`minute`

A specified minute.

`second`

A specified second.

`date`

The date to start calculation with.

`matchingPolicy`

Specifies the technique the search algorithm uses to find results. Default value is `.nextTime`.

`repeatedTimePolicy`

Specifies the behavior when multiple matches are found. Default value is `.first`.

`direction`

Specifies the direction in time to search. Default is `.forward`.

## Return Value

A `Date` representing the result of the search, or `nil` if a result could not be found.

## Discussion

If no such time exists, the next available time is returned (which could, for example, be in a different day than the nominal target date). The intent is to return a date on the same day as the original date argument.  This may result in a date which is backward than the given date, of course.

---

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)