我有以下内容:
NSString *dtString = @"2017-05-18 13:05:45";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *converted = [formatter dateFromString: dtString];
这会生成一个NSDate,其中:2017-05-18 12:05:45 UTC
落后一小时。如何让它与字符串完全匹配。
编辑:
我遇到的问题是,当我进行简单的日期比较时,如:
NSDate *inTenMinutes = [formatter dateFromString:@"2017-05-18 14:39:40"]; // NSlog will print this as 2017-05-18 13:39:40 UTC
NSDate *now = [NSDate date]; // Nslog prints this as 2017-05-18 14:30:35 UTC
BOOL isTenMinsDateEarlier = ([inTenMinutes compare:now] == NSOrderedAscending);
评估为YES,这没有任何意义。