gpt4 book ai didi

iphone - NSDateFormatter 只适用于模拟器?

转载 作者:行者123 更新时间:2023-12-03 20:29:32 27 4
gpt4 key购买 nike

我简单地尝试重新格式化日期:

 NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSDate *date = [[NSData alloc] init];
//Mon, 05 Apr 2010 14:27:48 -0700
[formatter setDateFormat:@"E, dd MMM yyyy HH:mm:ss Z"];
date = [formatter dateFromString:self.currentItemValue];

[formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
self.currentItem.pubDate = [formatter stringFromDate:date];
[formatter release];

它可以在模拟器上运行,但在设备上我只能得到(null)。

感谢您的帮助!

更多测试:

NSString *string = @"Fri, 12 Dec 2008 18:45:15 -0800";
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss Z"];
NSDate *date = [dateFormatter dateFromString:string];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
//here i got (null) on the device but it works on simulator...
NSLog(@"date %@", [dateFormatter stringFromDate:date]);

最佳答案

DyingCactus 是对的!

[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"] autorelease]];

解决了我的问题...谢谢!!!

关于iphone - NSDateFormatter 只适用于模拟器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2608520/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com