user972462
user972462

Reputation:

Date comparision with converting string to date

how to change string to time with time i am wring code as but no luck

NSString *comingdate = [sParams valueForKey:@"showdate"];
NSDateFormatter *dateformate = [[NSDateFormatter alloc]init];
[dateformate setDateFormat:@"yyyy-MM-dd"];
NSDate *todate = [dateformate dateFromString:comingdate];
NSLog(@"%@", todate);

/* from showdate i am getting date as yyyy-MM-dd but i awant to convert that string to date with time can any one give the clue or with clear code

Upvotes: 1

Views: 204

Answers (1)

Rama Rao
Rama Rao

Reputation: 1033

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);

Upvotes: 2

Related Questions