首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >本地化运行时间

本地化运行时间
EN

Stack Overflow用户
提问于 2011-04-06 07:43:57
回答 1查看 616关注 0票数 5

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-07 11:45:41

您想要使用类NSDateFormatter:

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

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5559910

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档