ios - NSDate is older than today -


i understand how compare 2 nsdate objects, e.g:

if ([olderdate compare:[nsdate date]] == nsorderedascending) {      //  } 

however compare date components, not time since time can make comparison inaccurate in case.

is possible compare day, month , year?

since ios 8, nscalendar has number of convenience methods sort of comparison.

for example, there's:

- (nsdate *)startofdayfordate:(nsdate *)date ns_available(10_9, 8_0); 

you can start of given day date (such [nsdate date] "now") , compare against that.

there's also:

- (nscomparisonresult)comparedate:(nsdate *)date1 todate:(nsdate *)date2 tounitgranularity:(nscalendarunit)unit ns_available(10_9, 8_0); 

you can call granularity nscalendarunitday comparison want directly.

there others, too. see nscalendar.h details, since these methods don't seem in class reference documentation, yet.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -