这段代码是没有问题的,能正常转换日期格式,但是坑在于formart使用的local是手机中设置的日历格式!
正常情况下formart转换出来的日期是2018-04-20,但是当你设置手机的日历为其他日历时(如:日本日历)它会转换成0037-04-20!!呵呵
NSDate* now = [NSDate date];
NSDateComponents* components = [[NSDateComponents alloc] init];
long long timeInterval = 180*24*60*60;
NSDate* endDate = [NSDate dateWithTimeIntervalSince1970:now.timeIntervalSince1970 - timeInterval];
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
formatter.dateFormat = @"yyyy-MM-dd";
[params setObject:[formatter stringFromDate:now] forKey:@"end-date"];
[params setObject:[formatter stringFromDate:endDate] forKey:@"start-date"];