문자열 날짜 @ "2016-10-19T12 : 37 : 15.0896144 + 00 : 00"int 초/분 /시/일/달/년으로 변환하는 방법.현재 날짜에서 해당 날짜를 만들 때 날짜 값을 얻는 방법
나는 날짜 값, 즉를 만들 수 있습니다 @ "2016-10-19T12 : 37 : 15.0896144 + 00 : 00"몇 초 몇 분 필요 "50 초"
후 보여줄 필요가
** 후 몇 시간 보여줄 필요가 후 "40 분"
을 보여 @ 몇 일 "삼일"몇 달 후
@ 표시해야합니다 후 20 "시간"
"사개월 @ 표시해야 " 몇 년 후
내가 작동하지 않는 시도 무엇 "이년"**
@ 표시해야합니다.
NSString* format = @"2016-10-19T12:37:15.0896144+00:00";
// Set up an NSDateFormatter for UTC time zone
NSDateFormatter* formatterUtc = [[NSDateFormatter alloc] init];
[formatterUtc setDateFormat:format];
[formatterUtc setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
// Cast the input string to NSDate
NSDate* utcDate = [formatterUtc dateFromString:[formatterUtc stringFromDate:timeString]];
// Set up an NSDateFormatter for the device's local time zone
NSDateFormatter* formatterLocal = [[NSDateFormatter alloc] init];
[formatterLocal setDateFormat:format];
[formatterLocal setTimeZone:[NSTimeZone localTimeZone]];
// Create local NSDate with time zone difference
NSDate* localDate = [formatterUtc dateFromString:[formatterLocal stringFromDate:utcDate]];
NSTimeInterval seconds = [[NSDate date] timeIntervalSinceDate:localDate];
귀하의 의견은 높이 평가됩니다.
NSDateIntervalFormatter와 NSDateComponentsFormatter를 살펴보십시오. – rmaddy
NSDateComponentsFormatter를 사용했습니다. – kiran