gpt4 book ai didi

iphone - 本地化耗时

转载 作者:可可西里 更新时间:2023-11-01 05:00:24 25 4
gpt4 key购买 nike

在我的应用程序中,我需要以 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com