현재 날짜와 10 일전의 날짜를 찾고 싶습니다. 현재 날짜를 찾는 방법을 알고 있습니다. 누구든지 현재 날짜에서 10 일 전에 날짜를 찾는 데 도움이됩니다.코코아 터치의 날짜
미리 감사드립니다.
현재 날짜와 10 일전의 날짜를 찾고 싶습니다. 현재 날짜를 찾는 방법을 알고 있습니다. 누구든지 현재 날짜에서 10 일 전에 날짜를 찾는 데 도움이됩니다.코코아 터치의 날짜
미리 감사드립니다.
NSDateComponents
을 사용하면 현재 날짜에서 일 수를 뺄 수 있습니다.
NSDate *today = [NSDate date];
NSDateComponents *sub_date = [[NSDateComponents alloc] init];
[sub_date setDay:-10];
NSDate *tenDaysAgo = [[NSCalendar currentCalendar] dateByAddingComponents:sub_date
toDate:today
options:0];
[sub_date release];
NSLog(@"Ten Days Ago: %@", tenDaysAgo);
dateWithTimeInterval:sinceDate:
을 사용하면 현재 날짜에서 10 일을 뺄 수 있습니다.
코드 예 :
NSDate *todayDate = [NSDate date];
NSDate *tenDaysAgoDate = [NSDate dateWithTimeInterval:-864000 sinceDate:todayDate];
864,000 네거티브 대신 전방, AGO 일 계산 설정 10 일 초를 나타낸다.
도움에 감사드립니다. – Sat
감사합니다. 잘 했어요. – Sat