Class

NSDateComponentsFormatter

A formatter that creates string representations of quantities of time. 一定量の時間の文字列表現を作成するフォーマッタ。

Declaration 宣言

@interface NSDateComponentsFormatter : NSFormatter

Overview 概要

An NSDateComponentsFormatter object takes quantities of time and formats them as a user-readable string. Use a date components formatter to create strings for your app’s interface. The formatter object has many options for creating both abbreviated and expanded strings. The formatter takes the current user’s locale and language into account when generating strings. NSDateComponentsFormatterオブジェクトは、時間量をとってそれらを利用者が読むことができる文字列として書式を整えます。日付構成要素フォーマッタを使ってあなたのアプリのインターフェイスに文字列を作成してください。フォーマッタオブジェクトは、短縮および伸長文字列の両方を作成するために多くのオプションを持っています。フォーマッタは、文字列を生成するとき現在のユーザのロケールと言語を考慮に入れます。

To use this class, create an instance, configure its properties, and call one of its methods to generate an appropriate string. The properties of this class let you configure the calendar and specify the date and time units you want displayed in the resulting string. Listing 1 shows how to configure a formatter to create the string “About 5 minutes remaining”. このクラスを使うには、インスタンスを作成して、それのプロパティを設定して、そしてそれのメソッドの1つを呼び出すことで適切な文字列を生成してください。このクラスのプロパティは、あなたにカレンダーを構成設定させて、あなたが結果文字列で表示されるのを望む日付と時刻の単位を指定させます。コード出力 1 は、 “About 5 minutes remaining” を作成するフォーマッタを構成設定する方法を示します。

Listing 1 Configuring a formatter object コード出力 1 フォーマッタオブジェクトの構成設定

NSDateComponentsFormatter *formatter = [[NSDateComponentsFormatter alloc] init];
formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleFull;
formatter.includesApproximationPhrase = YES;
formatter.includesTimeRemainingPhrase = YES;
formatter.allowedUnits = NSCalendarUnitMinute;
 
// Use the configured formatter to generate the string.
NSString* outputString = [formatter stringFromTimeInterval:300.0];

The methods of this class may be called safely from any thread of your app. It is also safe to share a single instance of this class from multiple threads, with the caveat that you should not change the configuration of the object while another thread is using it to generate a string. このクラスのメソッドは、あなたのアプリのあらゆるスレッドから安全に呼び出されるでしょう。またこのクラスの単一のインスタンスを複数のスレッドから共有するのは、あなたがそのオブジェクトの構成設定を別のスレッドがそれを文字列生成のために使っている間に変更すべきでないのを警告することで、同様に安全です。

Topics 話題

Formatting Values 書式設定値

Configuring the Formatter Options フォーマッタオプションを構成設定する

Constants 定数

Instance Properties インスタンスプロパティ

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

Relationships 関係

Inherits From 継承元

See Also 参照

Date Formatting 日付を書式設定する