如何随着时间将字符串更改为时间
我拧代码,但没有运气
NSString *comingdate = [sParams valueForKey:@"showdate"];
NSDateFormatter *dateformate = [[NSDateFormatter alloc]init];
[dateformate setDateFormat:@"yyyy-MM-dd"];
NSDate *todate = [dateformate dateFromString:comingdate];
NSLog(@"%@", todate);
/ * from showdate我得到的日期是yyyy-MM-dd,但是我想将该字符串转换为带时间的日期
谁能提供线索或清楚的代码
最佳答案
NSDate *firstDate=[[NSDate alloc]init];
NSString *comingdate = [sParams valueForKey:@"showdate"]; // yyyy-MM-dd
NSString *time = @"01:37:42"; // HH:mm:ss
comingdate = [comingdate stringByAppendingFormat:@" %@", time];
NSDateFormatter *dateformate = [[NSDateFormatter alloc] init];
[dateformate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *secondDate = [dateformate dateFromString:comingdate];
NSTimeInterval timeDifference = [secondDate timeIntervalSinceDate:firstDate];
NSLog(@"%f",timeDifference);
关于iphone - 将字符串转换为日期的日期比较,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7950359/