如果运行此代码,您可以看到1933-01-01 00:00:00 +0000的NSDate始终为空。请帮我解决一下。
NSString *date = @"1933-01-01 00:00:00 +0000";
NSString* dateString = [[NSString stringWithFormat:@"%@", date] stringByReplacingOccurrencesOfString:@" +0000" withString:@""];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"SGT"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
[dateFormatter setLocale:[NSLocale systemLocale]];
[dateFormatter setFormatterBehavior:NSDateFormatterBehaviorDefault];
NSDate* sgtDate = [dateFormatter dateFromString:dateString];
NSLog(@"SGT Date: %@",sgtDate);
答案 0 :(得分:0)
尝试
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT+08:00"]];
而不是
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"SGT"]];