我正在尝试将字符串转换为日期,但它返回null。
NSString *offer_publishdate*=@"15/10/2013";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMdd"];
NSDate *date = [dateFormat dateFromString:offer_publishdate];
NSLog(@"date:%@",date);
答案 0 :(得分:1)
请选择确切的日期格式
NSString *offer_publishdate*=@"15/10/2013";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy"];
NSDate *date = [dateFormat dateFromString:offer_publishdate];
NSLog(@"date:%@",date);
答案 1 :(得分:0)
试试这种方式......
NSString *offer_publishdate*=@"15/10/2013";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy"];
NSDate *date = [dateFormat dateFromString:offer_publishdate];
答案 2 :(得分:0)
将日期格式化程序从@"yyyyMMdd
更改为@"dd/MM/yyyy"