我是新來的ios編程。使用initWithTimeInterval遇到問題
我想通過下面的代碼得到死亡日期。 但是,我得到了意想不到的結果。
在下面的示例代碼,一個人的出生日期是1899年12月31日和這個人的死亡年齡爲80
所以,我希望這個人的deathdate是1979年12月31日。 但是,我得到的結果是1843-11-05 08:31:44 +0000。
任何人都可以告訴我這段代碼有什麼問題嗎?
謝謝!
NSInteger year = [_selectedDeathAge intValue];
NSLog(@"%d", year); //80
NSLog(@"%@", _selectedBirthDate);//(NSDate)1899-12-31 15:00:00 +0000
NSDate *deathDate = [_selectedBirthDate initWithTimeInterval:year * 365 * 24 * 60 * 60 sinceDate:_selectedBirthDate];
NSLog(@"%@", deathDate);//(NSDate)1843-11-05 08:31:44 +0000
非常感謝!有用!!我在4分鐘內接受你的回答。 – crzyonez777