Reputation: 819
Ive been racking my brains with no luck. Could someone please tell my how i would convert this string:
NSString *dateTimeStr =[[self.responseArray objectAtIndex:indexPath.row]objectForKey:@"date_time"];
2014-04-13T17:00:00+11:0
into a NSDate
? and time format ?
how can i covert this date into time format ?
here is my code:
NSString *dateTimeStr =[[self.responseArray objectAtIndex:indexPath.row]objectForKey:@"date_time"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
[dateFormatter setDateFormat:@"yyyy-MM-ddHH:mm:ss"];
NSDate *date = [dateFormatter dateFromString:dateTimeStr];
NSLog(@"date %@", date);
NSTimeInterval seconds = [date timeIntervalSinceReferenceDate];
in console
NSLog(@"seconds==> %f", seconds);
i have time in miliseconds then how can i take out minutes/hours/
?
Upvotes: 0
Views: 1620
Reputation: 46533
NSString *dateString = @"2014-04-13T17:00:00+11:00";
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate *date = [dateFormatter dateFromString:dateString];
NSDateComponents *dateComponents = [[NSCalendar currentCalendar]
components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit
fromDate:date];
NSInteger year = [dateComponents year];
NSInteger month = [dateComponents month];
NSInteger day = [dateComponents day];
Upvotes: 3