0
我有時間部分作爲一個字符串,我想解析它到日期,因爲我擔心日期的時間部分。但是當我用給定的格式解析它時,結果是零。我應該如何解析我的時間字符串?解析時間字符串到NSDate返回無
時間字符串: 23:59
方法:
+(NSDate*)getDateFromStringProfile:(NSString*)strDate
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
[dateFormat setDateFormat:@"HH:mm"];
[dateFormat setTimeZone:timeZone];
NSDate *result =[dateFormat dateFromString:strDate];
return result;
}
結果:零
嘗試使用'NSLocale'爲'NSDataFormatter'設置語言環境。 – 2015-04-02 20:48:51
請參閱http://stackoverflow.com/questions/6613110/what-is-the-best-way-to-deal-with-the-nsdateformatter-locale-feature – 2015-04-03 01:03:43