Sir*_*tty 3 cocoa localization nsdate
我正在使用NSDate来获取诸如"18 Jun 09"之类的字符串,代码如下:
NSDate *theDate = [NSDate date];
NSString *dateString = [theDate descriptionWithCalendarFormat:@"%d %b %y"
timeZone:nil
locale: nil];
Run Code Online (Sandbox Code Playgroud)
这有效,但只会产生英文输出.我需要将输出本地化为用户的默认语言.
Cocoa(在这种情况下是Mac OS X 10.4,10.5)是否为这种本地化提供了便利,还是我必须手动本地化每天和每个月的名字?
(我提供了一个区域设置,但是虽然确实提供了日期的特定于区域设置的顺序,但它似乎不会对日期月份名称进行任何本地化.)
Dem*_*emi 22
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:118800];
NSString *formattedDateString = [dateFormatter stringFromDate:date];
NSLog(@"formattedDateString for locale %@: %@", [[dateFormatter locale] localeIdentifier], formattedDateString);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13393 次 |
| 最近记录: |