macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

dateWithNaturalLanguageString:locale:

ローカライズされた自然言語で時間を作って返します
+(NSDate *)dateWithNaturalLanguageString:(NSString *)string:
             locale:(NSDictionary *)localeDictionary:

解説

ローカライズされた自然言語で時間を作って返します。
【localeDictionary】ローカライズ辞書
● NSDateTimeOrdering 年、月、日、時間の並び順の文字列
2001年12月31日午前10時を表す場合 @"MDYH" なら @"12/31/01 10"
2001年12月31日午前10時を表す場合 @"MDYHM" なら @"12/31/01 10:30"

● NSEarlierTimeDesignations 「前の」を表す文字列(初期設定は"prior" "last" "past" , "ago")の配列。年、月、日、曜日で有効です。
● NSHourNameDesignations 「時間の文字列と時間を表す名称の文字列の配列」の配列。
初期設定は(0, midnight), (12, noon, lunch), (10, morning), (14, afternoon), (19, dinner)です。
● NSLaterTimeDesignations 「次の」を表す文字列(初期設定は"next")の配列。年、月、日、曜日で有効です。
● NSNextDayDesignations 明日を表す文字列(初期設定は"tomorrow")の配列。@"ashita at asa"
● NSNextNextDayDesignations 明後日を表す文字列(初期設定は"nextday")の配列。@"asatte at asa"
● NSPriorDayDesignations 昨日を表す文字列(初期設定は"yesterday")の配列。@"kinou at asa"
● NSThisDayDesignations 今日を表す文字列(初期設定は"today")の配列。@"kyou at hiru"

NSYearMonthWeekDesignations An array of strings that specify the word for year, month, and week in the current locale. The defaults are "year," "month," and "week."

返り値

( NSDate * )

時間

引数

( NSString * )string

時間を表す文字列

( NSDictionary * )localeDictionary

ローカライズ辞書

クラス

NSDate

Class Methods

使用可能

10.0

参照

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSArray *last = [NSArray arrayWithObjects:@"sugita",@"maeno", nil];
NSArray *next = [NSArray arrayWithObjects:@"tugino", nil];

NSArray *asa = [NSArray arrayWithObjects:@"8",@"asa", nil];
NSArray *hiru = [NSArray arrayWithObjects:@"12",@"hiru", nil];
NSArray *hourName = [NSArray arrayWithObjects:asa,hiru, nil];

NSArray *today = [NSArray arrayWithObjects:@"kyou", nil];
NSArray *yesterday = [NSArray arrayWithObjects:@"kinou", nil];
NSArray *tomorrow = [NSArray arrayWithObjects:@"ashita", nil];
NSArray *nextday = [NSArray arrayWithObjects:@"asatte", nil];
NSArray *dateTimeOrder = [NSArray arrayWithObjects:@"MDYH", nil];

NSArray *month = [NSArray arrayWithObjects:@"tuki",@"month", nil];
NSArray *ymw = [NSArray arrayWithObjects:month, nil];

NSDictionary *dic= [[NSDictionary alloc] initWithObjectsAndKeys:
                //last,@"NSEarlierTimeDesignations",
               //next,@"NSLaterTimeDesignations",
                 hourName,@"NSHourNameDesignations",
                 tomorrow,@"NSNextDayDesignations",
                 nextday,@"NSNextNextDayDesignations",
                 yesterday,@"NSPriorDayDesignations", 
                 today,@"NSThisDayDesignations",
                 //@"MDYHM",@"NSDateTimeOrdering",
                 //ymw,@"NSYearMonthWeekDesignations",
		nil];
NSDate *theDate;
theDate = [NSDate dateWithNaturalLanguageString:@"kinou at asa" locale:dic];
[myOutlet setStringValue:[theDate description]];
NSLog(@"The current date and time is %@", [NSCalendarDate date]);
}

@end