简体   繁体   English

本地化经过的时间

[英]localizing elapsed time

In my application I need to show elapsed time in mm:ss format. 在我的应用程序中,我需要以mm:ss格式显示已用时间。 Now, we have to localize the application. 现在,我们必须本地化应用程序。 How should we localize this elapsed time? 我们该如何定位这段经过的时间?

You want to use the class NSDateFormatter: 您想使用NSDateFormatter类:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM