Ios NSDateFormatter以“格式”打印当前日期;年月日hh:mm“;任何地域

Ios NSDateFormatter以“格式”打印当前日期;年月日hh:mm“;任何地域,ios,nsdateformatter,Ios,Nsdateformatter,您好,我想在任何语言环境中将当前日期打印为M/yyyy hh:mm 我使用的方法是将currentLocale作为locale中的选项 + (NSString *)dateFormatFromTemplate:(NSString *)template options:(NSUInteger)opts locale:(NSLocale *)locale 但它提出了具体的安排 例如,在美国地区,日期和时间之间有一个逗号 怎么办????我不想在每个区域设置中使用逗号,只想在每个区域设置中使用空格…如

您好,我想在任何语言环境中将当前日期打印为
M/yyyy hh:mm

我使用的方法是将
currentLocale
作为locale中的选项

+ (NSString *)dateFormatFromTemplate:(NSString *)template options:(NSUInteger)opts locale:(NSLocale *)locale
但它提出了具体的安排

例如,在美国地区,日期和时间之间有一个逗号


怎么办????我不想在每个区域设置中使用逗号,只想在每个区域设置中使用空格…

如果要将日期格式化为特定格式,那么为什么要使用
dateFormatFromTemplate:
?该方法的目的是从通用格式中为您提供特定于语言环境的格式

只需使用普通的
NSDateFormatter
功能:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"M/yyyy hh:mm"];
NSDate *now = [NSDate date];
NSString *formattedDate = [formatter stringFromDate:now];