2012-12-26 2 views
1

차 (NSTimeInterval)는

NSDate *today = [NSDate date]; 
NSDate *tomarow = [today dateByAddingTimeInterval:60*60*24]; 
NSDate *nextday = [NSDate dateWithTimeInterval:60*60*24 sinceDate:today]; 
+0

무엇을 찾았습니까 ?? –

+0

@InderKumarRathore - 두 문장 모두 동일한 값을 얻고 있습니다. 차이점은 무엇입니까 – ray1th

+1

@ ray1th 내 대답을 확인하십시오 !! –

답변

5

두 방법의 유일한 차이가있는 두 문장의 차이 무엇 하나는 클래스 메소드이고 다른 하나는 인스턴스 메소드입니다. 클래스 메소드에서

: 날짜 : 2012년 12월 27일 09

// Today's Date 
NSDate *today = [NSDate new]; 

// Date With Class Method 
NSDate *tomorrow1 = [NSDate dateWithTimeInterval:60*60*24 sinceDate:today]; 
NSLog(@"Date from class method: %@", tomorrow1); 

// Date With Instance Method 
NSDate *tomorrow2 = [today dateByAddingTimeInterval:60*60*24]; 
NSLog(@"Date from instance method: %@", tomorrow2); 

위의 코드는 다음과 같이 출력을 제공합니다 : 코드에 따라

는 두 가지 방법을 사용하는 방법을 보여줍니다 : 인스턴스 메소드에서 35:15 0000

날짜 : 2012년 12월 27일 9시 35분 15초 0000

자세한 내용은 NSDate

+0

네거티브 vale'-60 * 60 * 24' –

+0

@InderKumarRathore를 전달하여 동일한 작업을 수행 할 수 있습니까? tomarrow 2012-12-25 09:46:50 +0000, nextday 2012-12-25 09:46 : 50 +0000 !! 뭐가 문제 야? –

+1

아무 것도 잘못되었습니다. 지금은 창가에 있으므로 확인할 수 없습니다. 그래서 내가 너 한테 말했지. 어쨌든 +1 f –