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

date(bySettingUnit:value:of:options:)

Returns a new date representing the date calculated by setting a specific component of a given date to a given value, while trying to keep lower components the same. 与えられた日付の指定構成要素をある与えられた値に設定して、一方でより低い構成要素を同じままに保とうとすることによって計算された日付を表している新しい日付を返します。

Declaration 宣言

func date(bySettingUnit unit: NSCalendar.Unit, 
    value v: Int, 
       of date: Date, 
  options opts: NSCalendar.Options = []) -> Date?

Parameters パラメータ

unit

The unit to set with the given value. For possible values, see NSCalendar.Unit. 与えられた値で設定することになる単位。可能な値として、NSCalendar.Unitを見てください。

v

The value to set for the given calendar unit. 与えられたカレンダー単位に対して設定する値。

date

The date to use to perform the calculation. 計算を実行するために使う日付。

opts

Options for the calculation. For possible values, see NSCalendar.Options. 計算に対するオプション。可能な値として、NSCalendar.Optionsを見てください。

Return Value 戻り値

A new NSDate instance representing the date calculated by setting a specific component of a given date to a given value. If the unit already has that value, this may result in a date which is the same as the given date. If no such time exists for the specified components, the next available date is returned, which may be on a different calendar day. ある新しいNSDateインスタンス、与えられた日付の特定の構成要素をある与えられた値に設定することによって計算された日付を表しています。その単位がすでにこの値ならば、これは与えられた日付と同じ日付という結果になるかもしれません。そのような時間が指定された構成要素それらに対して存在しないならば、次の利用可能な日付が返されます、それは異なる暦日であるかもしれません。

Discussion 議論

Changing a component's value often requires higher or coupled components to change as well. For example, setting the weekday to "Thursday" will require the day component to change its value, and possibly the month and year as well. You can use the nextDate(after:matching:value:options:) method to specify more precise behavior for determining the next or previous date for a given date component. ある構成要素の値を変更することは、しばしばより高位または連動する構成要素もまた変更することを必要とします。例えば、weekdayを "Thursday" に設定することは、day構成要素をそれの値に変更することを必要とするでしょう、そしてことによるとmonthyearもまた。あなたはnextDate(after:matching:value:options:)メソッドを使って、ある与えられた日付構成要素の次または前の日付を決定することに対してより正確な挙動を指定できます。

See Also 参照

Calculating Dates 日付を計算する

Related Documentation 関連文書