I'm confused with one question. I don't understand where I made mistake
I needed make minimumdate for my UIDatePicker near 1810 year. So I try make it like
datePicker.minimumDate = [[NSDate alloc] initWithTimeIntervalSince1970: - (60 * 60 * 24 * 365 * 160)];
But I get wrong minimumdate:

So I went the other way and solved the problem
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps = [NSDateComponents new];
comps.year = -160;
datePicker.minimumDate = [calendar dateByAddingComponents:comps toDate:[NSDate dateWithTimeIntervalSince1970:0] options:0];
But I can'nt understand why in the first case I get wrong minimumdate
datePicker.minimumDate = [[NSDate alloc] initWithTimeIntervalSince1970: - (60 * 60 * 24 * 365 * 160)];
160 Years are not 60 sec * 60 min * 24 hours * 365 days.
You did not take consideration of various factors, one of the easiest to know is leap year.
Edit:
Use 60.0 * 60 * 24 * 365 * 160 to make one of then float, so the result will be float as you may exceed the int32(ios) range.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With