Contents

string(from:to:)

Returns a formatted string based on the time difference between two dates.

Declaration

func string(from startDate: Date, to endDate: Date) -> String?

Parameters

  • startDate:

    The start time. This parameter must not be nil.

  • endDate:

    The end time. This parameter must not be nil.

Return Value

A formatted string representing the specified time information.

Discussion

This method calculates the elapsed time between the startDate and endDate values and uses that information to generate the string. For example, if there is exactly one hour and ten minutes difference between the start and end dates, generating an abbreviated string would result in a string of “1h 10m”.

See Also

Formatting Values