如何随时间改变字符串 我正在拧代码,但没有运气
NSString *comingdate = [sParams valueForKey:@"showdate"];
NSDateFormatter *dateformate = [[NSDateFormatter alloc]init];
[dateformate setDateFormat:@"yyyy-MM-dd"];
NSDate *todate = [dateformate dateFromString:comingdate];
NSLog(@"%@", todate);
来自showdate的/ *我的日期是yyyy-MM-dd,但是我很想把这个字符串转换成日期与时间 任何人都可以提供线索或明确的代码
答案 0 :(得分:2)
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);