我有以下字符串"Mar 13, 2013 05:30pm"
。我想将其转换为NSDate
对象。
我尝试了以下方法,但它无效。
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMM:dd, YYYY hh:mm:aa"];
date=[dateFormatter dateFromString:dateString];
答案 0 :(得分:4)
NSDateFormatter *dFormate = [[NSDateFormatter alloc] init];
[dFormate setDateFormat:@"MM dd, yyyy hh:mma"];
[dFormate setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
NSString *dateStr = @"Mar 13, 2013 05:30pm";
NSDate *date = [dFormate dateFromString:dateStr];
NSLog(@"Date : %@", date);
答案 1 :(得分:1)
试试这个: -
NSString *stringDate = @"Mar 13, 2013 05:30pm";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMM dd, yyyy hh:mmaa"];
NSDate *date=[dateFormatter dateFromString:stringDate];
NSLog(@"Date : %@",date);
希望它可以帮助你..