Type Method 型メソッド

dateFormat(fromTemplate:options:locale:)

Returns a localized date format string representing the given date format components arranged appropriately for the specified locale. 指定されたロケールに対して適切に整えられた、与えられた日付書式設定構成要素を表している、ローカライズされた日付書式設定文字列を返します。

Declaration 宣言

class func dateFormat(fromTemplate tmplate: String, 
              options opts: Int, 
               locale: Locale?) -> String?

Parameters パラメータ

template

A string containing date format patterns (such as “MM” or “h”). 日付書式設定パターンを含んでいる文字列(例えば “MM” や “h” など)。

For full details, see Date and Time Programming Guide. 完全な詳細として、Date and Time Programming Guideを見てください。

opts

No options are currently defined. オプションは現在は定義されません。

locale

The locale for which the template is required. 雛形が必要とされるロケール。

Return Value 戻り値

A localized date format string representing the date format components given in template, arranged appropriately for the locale specified by locale. templateにおいて与えられる日付書式設定構成要素を表している、ローカライズされた日付書式設定文字列、localeによって指定されるロケールに対して適切に整えられます。

The returned string may not contain exactly those components given in template, but may—for example—have locale-specific adjustments applied. 返される文字列は、templateにおいて与えられるそれら構成要素をきっちり含んでいないかもしれません、しかし — 例えば — ロケール特有の調整が適用されるかもしれません。

Discussion 議論

Different locales have different conventions for the ordering of date components. You use this method to get an appropriate format string for a given set of components for a specified locale (typically you use the current locale—see current). 異なるロケールは、日付構成要素の順番に対して異なる慣例を持ちます。あなたはこのメソッドを使って、指定されたロケールに対して、与えられたひとそろいの構成要素のために、適切な書式設定文字列を取得します(大抵はあなたは現在のロケールを使います — currentを見てください)。

The following example shows the difference between the date formats for British and American English: 以下の例は、British と American English に対する日付書式設定の間の差を示します:


let usLocale = Locale(identifier: "en_US")
let gbLocale = Locale(identifier: "en_GB")
let template = "yMMMMd"
 
let usDateFormat = DateFormatter.dateFormat(fromTemplate: template, options: 0, locale: usLocale)!
// Date format for English (United States): "MMMM d, y"
let gbDateFormat = DateFormatter.dateFormat(fromTemplate: template, options: 0, locale: gbLocale)!
// Date format for English (United Kingdom): "d MMMM y"

See Also 参照

Managing Formats and Styles 書式設定とスタイルを管理する