简体   繁体   English

如何本地化时间段(iOS / OSX)

[英]How to localise a time period (iOS/OSX)

Anyone know of a way to localize a time period (eg 2.5 days or 6 months) 任何人都知道一种定位时间段的方法(例如2.5天或6个月)

It looks like the solution is to use a stringsdict file - but this strikes me as a problem that must have been solved already? 看起来解决方案是使用stringsdict文件 - 但这对我来说是一个必须已经解决的问题?

Thanks 谢谢

This is what NSDateComponentsFormatter does. 这就是NSDateComponentsFormatter所做的。 An example from the docs: 来自文档的一个例子:

NSDateComponentsFormatter* formatter = [[NSDateComponentsFormatter alloc] init];
formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleFull;
formatter.includesApproximationPhrase = YES;
formatter.includesTimeRemainingPhrase = YES;
formatter.allowedUnits = NSCalendarUnitMinute;
// Use the configured formatter to generate the string.
NSString* outputString = [formatter stringFromTimeInterval:300.0];

gives "About 5 minutes remaining". 给出“剩余约5分钟”。

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

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