我试图将字符串转换为日期时间,并将日期时间转换为字符串,它正在工作,但有些错误。我没有得到正确的甲酸盐。 我的例外结果应该是: like this.02/02/2013 05:24PM time should be 12 hours formate;
NSString *dateTime = @"2013-02-02 15:54:31";
int time=[[temp objectForKey:@"created"]intValue];
NSLog(@"Time=%d",time);
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"YYYY-MM-DD HH:MM:SS"];
[dateFormat setTimeZone:[NSTimeZone timeZoneWithName:dateTime]];
NSDate *date = [dateFormat dateFromString:dateTime];
NSLog(@"Nsdate=%@",date);
// Convert date object to desired output format
[dateFormat setDateFormat:@"hh:mma"];
dateTime = [dateFormat stringFromDate:date];
[dateFormat release];
NSLog(@"DateTime=%@",dateTime);
--------------------
NSLogs :
Time=2013
DateTime=2013-02-02 17:06:09
Nsdate=2013-01-02 11:30:00 +0000//it's not correct date
DateTime=02/01/2013 05:00PM//it's not correct date and time//
-------------
my excepting result should be like this:
DateTime :02/02/2013 05:24PM
如果您有任何想法,请剪切您的想法,它会帮助我。