【发布时间】:2014-05-09 11:59:26
【问题描述】:
我的日期类似于"payment_date" = "03:12:00 May 06, 2014 MDT";。
但我想把这些数据转换成NSDate,比如"06-05-2014"
请帮帮我, 不知道怎么处理..
我从Converting NSString to NSDate (and back again)得到了答案
__block NSDate *detectedDate;
//Detect.
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingAllTypes error:nil];
[detector enumerateMatchesInString:t_date
options:kNilOptions
range:NSMakeRange(0, [t_date length])
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop)
{ detectedDate = result.date;
NSDate *d=result.date;
}
];
【问题讨论】:
-
stackoverflow 上已有解决方案。
-
你能给我那个链接吗?
-
@user3620252:stackoverflow.com/questions/10570593/…
-
确保您阅读并理解了 NSDate 的文档。这里有大量的问题,对 NSDate 的误解使人们认为结果实际上是正确的却得到了错误的结果。
标签: ios objective-c