iphone - 本地化耗时

标签 iphone cocoa-touch ios localization

在我的应用程序中,我需要以 mm:ss 格式显示耗时。现在,我们必须本地化应用程序。我们应该如何本地化这个耗时?

最佳答案

你想使用 NSDateFormatter 类:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];

NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:118800];

// Specifying a locale only for the purpose of this example
// if you don't specify one, it will use the user's locale, which is what you want
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:usLocale];

NSLog(@"Date for locale %@: %@",
      [[dateFormatter locale] localeIdentifier], [dateFormatter stringFromDate:date]);
// Output:
// Date for locale en_US: 4:00 AM

关于iphone - 本地化耗时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5559910/

相关文章:

iphone - 访问实例变量的语法? ( Objective-C )

ios - CoreData 重复结果,时间戳谓词

iphone - 您已经购买了此订阅。点击“购买”以续订或延期

iphone - 您希望 iPhone 库为您做什么?

iphone - iPhone 应用程序上的图形

ios - 如何在 Swift 中限制文本字段中的数字?

ios - 如何在 TableView 的每个部分中添加摘要条目

iphone - 在 iPhone 上实现动态文本

iphone - 如何为图层 shadowOpacity 设置动画?

iOS:以编程方式在 UITextView 中向上、向下、向左和向右移动光标