The deal is I want a NSDate representation of the date 18th of June 1978. I have tried to init NSDate like
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
self.dateFormatter.timeStyle = NSDateFormatterNoStyle;
self.startDate = [dateFormatter dateFromString:@"19/06/78"];
NSLog(@"%@", self.startDate);
This produces the right date when the iPhone is set to Danish in the International settings. It does not work with a iPhone set to i.e. english/american settings.
Notice the extra day (19) because denmark is in GMT +1 and i think the NSDate defaults to time 23:00:00. That indicates that something i not working as intended.
我希望,上述日期(18/06/1978)代表了一种NSDate Object,而不论时间区、地方和国际环境如何。
如何做到这一点?
<><>Edit>:
So Ole Begemann s answer seemed to resolve my issue. His solution did create the correct date both on a device in USA International settings and en European international settings. But when Apple should review the app the date created was 17th of June 1978. This makes sence since I m setting timezone to GMT +0000. And Cupertino is like GMT -0007 or so. So this would give a day earlier.
因此,我的问题是: 我想18-06-1978年,不管当地情况如何,该装置在身体上或环境上都是明智的。
我想要做的是确定18个起始日期。 1978年,后来在我看来,无论装置的时间区或地点如何,该日期都成为像“780618”(yMMd)这样的严格格式。 一切途径都必须是“780618”,因为这是我评估的关键起点。
因此,我也许会错过这个问题。 我不应试图在任何地方强制使用同一日期,而应接受时间区,并试图将NSDateFormatter混为一谈,以达到正确日期。
So basically: What I want is THE NSDate instance that formats to "780618" everywhere - in any timezone with any international device settings.
如何做到这一点?