NSDateFormatter日期问题

时间:2011-09-20 08:46:10

标签: iphone objective-c ios xcode

我正在使用Tapku库进行日期目的。使用DateFormatter选择日期后。我得到了约会,它在印度工作正常。但是当客户(美国)在所选日期前一天检查它给出的日期。

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,但解决办法是在你的代码中设置gmtTimeZone。就像这个

以下方法..   - (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)d {

  NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];///set GMT Time

NSDateFormatter *df = [[[NSDateFormatter alloc] init]autorelease];
[df setTimeZone:gmt];
[df setDateFormat:@"MM-dd-yyyy"];
NSString *dateNTime = [NSString stringWithFormat:@"%@", [df stringFromDate:d]];
NSLog(@"%@",dateNTime);

}

答案 1 :(得分:0)

最好的方法是获取区域设置并设置默认设备/系统区域设置。请参阅Apple文档 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DatesAndTimes/DatesAndTimes.html