我已经查看了几乎所有关于NSDate转换的帖子,但是没有成功解决我的问题 .

Background :我想在CalendarView中渲染值时简单地比较NSDate(没有时间)值 . 但是,当我从服务器转换ISO日期时,它实际上返回上一个日期,因为我猜是GMT偏移值 . 但是,我只想表彰从服务器传递的年,月,日 .

Code

来自服务器的值: date: "2014-09-26T00:00:00.000Z"

Objective-C代码转换为NSDate . 我正在使用Soffes library来处理ISO日期转换 .

NSTimeZone *timezone = [NSTimeZone timeZoneWithName:@"UTC"]; NSDate *date = [NSDate dateWithISO8601String:myDate timeZone:&timezone usingCalendar:nil]; NSDate *dateWithoutTime = [NSDate dateWithOutTime:date];

无时间返回日期的代码:

NSDateComponents* comps = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:date]; return [[NSCalendar currentCalendar] dateFromComponents:comps];

Current Results

ISO日期来自字符串

po date 2014-09-26 00:00:00 +0000

没有时间的日期

po dateWithoutTime 2014-09-25 06:00:00 +0000

关于我如何仍然尊重从服务器传递的年,月,日的任何建议?