dateformatter 在模拟器中有效,但在设备上无效

发布于 2024-09-07 12:17:54 字数 535 浏览 2 评论 0原文

这段代码适用于模拟器...但不适用于我的 iPod touch...在 iPod 上我看到未格式化的日期:-(

 NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] retain];

//Date Before = Sun, 20 Jun 2010 06:00:00 +020

        [formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];
        NSDate *d = [formatter dateFromString:string];
        [formatter setDateFormat:@"dd.MM.yyyy HH:mm"];
        string = [NSString stringWithString:[formatter stringFromDate:d]];
        [currentDate appendString:string];

this code works on simulator ... but not on my ipod touch... on ipod I see the unformated date :-(

 NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] retain];

//Date Before = Sun, 20 Jun 2010 06:00:00 +020

        [formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];
        NSDate *d = [formatter dateFromString:string];
        [formatter setDateFormat:@"dd.MM.yyyy HH:mm"];
        string = [NSString stringWithString:[formatter stringFromDate:d]];
        [currentDate appendString:string];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗼ふ静 2024-09-14 12:17:54

在设备上,您需要明确设置您的区域设置。

插入这一行:

[formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];

紧接着:

[formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];

On the device, you need to explicitly set your locale.

Insert this line:

[formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];

Right after:

[formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文