我发现在xcode模拟器中有一个很棒的设置,可以更改当前位置,从而模拟基于位置的测试。
然而,当我尝试使用NSDateFormatter获取日期时,本地日期仍然是太平洋标准时间。我所在的时区是太平洋时间。
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle]; // Jan 1, 2010
[dateFormatter setTimeStyle:NSDateFormatterShortStyle]; // 1:43 PM
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:usLocale];
[usLocale release];
NSDate *testDate = [NSDate date];
NSLog(@"Local date: %@", [dateFormatter stringFromDate:testDate]);
根据文档,stringFromDate应该使用接收器当前的设置,这应该使用日本东京的时区。
这是预期的吗?