I have two nsdatecomponent object, and I want a substract the time of my first object with the time of the seconde object.
example: DateComponentObject1 = DateComponentObject1 - DateComponentObject2
so, if I have 3 hour in DateComponentObject1 and 1 hour in DateComponentObject2, I have 2 hour at the end in the DateComponentObject1.
How I can do this?
NSCalendar
object that corresponds to the calendar used by your NSDateComponent
instances. DateComponentObject1
to an NSDate
with -[NSCalendar dateFromComponents:]
. DateComponentObject2
by -1
(because you want to subtract them from the first date). DateComponentObject2
to the date object with -[NSCalendar dateByAddingComponents:toDate:options:]
. NSDate
object into date components with -[NSCalendar components:fromDate:]
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.