NSDateFormatter区域设置 [英] NSDateFormatter Locale

查看:88
本文介绍了NSDateFormatter区域设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为NSDateFormatter设置区域设置?我已经尝试了以下代码并且它无法正常工作。

How to set Locale for NSDateFormatter? I've tried the below code and its not working.

- (NSString *)localizedStringWithFormat:(NSString *)format {

    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:format];
    NSCalendar *cal = [NSCalendar currentCalendar];
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier: @"fr_FR"];
    cal.locale = locale;
    df.calendar = cal;
    return [df stringFromDate:self];
}

请告诉我如何使这项工作。

Please let me know how to make this work.

谢谢。

推荐答案

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *locale = [[NSLocale alloc] 
                     initWithLocaleIdentifier:@"he"];
[dateFormatter setLocale:locale];

这篇关于NSDateFormatter区域设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆