Instance Method インスタンスメソッド

string(from:to:)

Returns a formatted string based on the specified start and end dates. 指定された開始および終了日付に基づいて書式設定された文字列を返します。

Declaration 宣言

func string(from fromDate: Date, 
         to toDate: Date) -> String

Parameters パラメータ

fromDate

The start date. This date appears first in the resulting string. 開始日付。この日付は結果文字列において最初に現れます。

toDate

The end date. This date appears last after the hyphen in the resulting string. 終了日付。この日付は結果文字列においてハイフンの後で最後に現れます。

Return Value 戻り値

A formatted string representing the specified date interval. 指定された日付間隔を表している書式設定された文字列。

Discussion 議論

The formatter includes both fromDate and toDate in the resulting string only when there is enough of a difference in their values to warrant the inclusion of both. If the date and time difference cannot be adequately displayed, the formatter displays one date value. For example, if the timeStyle property was set to DateIntervalFormatter.Style.none, the two dates would need to be at least one day apart in order for both to be displayed. フォーマッタは、両方を含める理由となる十分な差がある場合にのみ、fromDatetoDateの両方を結果文字列に含みます。日付と時刻の差が満足に表示されることができないならば、フォーマッタは1つの日付値を表示します。例えば、timeStyleプロパティがDateIntervalFormatter.Style.noneに設定されたならば、2つの日付は、両方が表示されるために少なくとも1日は離れる必要があるでしょう。