startOfDay(for:)

Returns the first moment of a given Date, as a Date.

iOS
8.0+
macOS
10.10+
tvOS
9.0+
watchOS
2.0+
func startOfDay(for date: Date) -> Date

Parameters

date

The date to search.

Returns

The first moment of the given date.

For example, pass in Date(), if you want the start of today. If there were two midnights, it returns the first. If there was none, it returns the first moment that did exist.