试图将“ expires_date”字符串转换为NSDate对象。
issue:NSDate对象=无。
有什么建议吗?
#define K_RECEIPT_TIMEZONE_FORMAT @"yyyy-MM-dd HH:mm:ss"
-(NSDate*)expires_date{
NSMutableDictionary * dictionary = [_dictionary mutableCopy];
NSString * date_string = [[dictionary valueForKey:@"expires_date"] copy];
NSDateFormatter *dateFormatter = [IAPSKReceipt formatter];
NSDate *date = [dateFormatter dateFromString:date_string];
return date;
}
+(NSDateFormatter*)formatter{
NSDateFormatter * RFC3339DateFormatter = [[NSDateFormatter alloc] init];
if (@available(iOS 10.0, *)) {
RFC3339DateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
} else {
RFC3339DateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
}
RFC3339DateFormatter.dateFormat = K_RECEIPT_TIMEZONE_FORMAT;
RFC3339DateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
return RFC3339DateFormatter;
}
您可能要研究针对您要执行的操作而量身定制的ISO8601DateFormatter:
https://developer.apple.com/documentation/foundation/iso8601dateformatter