これを以前のバージョン(iOS4.0.1以前)で使っていた形式で文字列として取り出す方法。
下記は、ローカル時刻は日本、"YYYY/MM/DD HH:MM:SS"の形式で文字列変換する方法。
NSDate *today = [NSDate date];
NSLocale *locale_ja;
locale_ja = [[[NSLocale alloc] initWithLocaleIdentifier:@"ja_JP"] autorelease];
NSDateFormatter *formatter;
formatter = [[[NSDateFormatter alloc]init] autorelease];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
[formatter setLocale:locale_ja];
NSLog(@"Date %@", [formatter stringFromDate:today]);
タグ:iPhone
【NSDateの最新記事】