我可能会因为一个愚蠢的问题而发疯。
我有 3 个字符串:年、月、日。我需要根据 currentLocale 获得正确格式的日期,因此,如果 currentLocale localeIdentifier 是 en_US 我的 dateFormat 应该是:
月/日/年
如果是 fr_FR,则日期格式应为 dd/MMM/yyyy
我不认为唯一的方法是获取 currentLocale localeIdentifier 并从一堆 if then 开始。
提前致谢。
Max
如果我理解你的问题,你想设置你的NSDateFormatter
用户设备的区域设置。为此,你可以这样做:
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setLocale:[NSLocale currentLocale]];
NSDate *date = [NSDate date];
NSString *dateString = [dateFormatter stringFromDate:date];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)