How does one subtract hours from an NSDate?

后端 未结 7 1439
长发绾君心
长发绾君心 2020-12-09 14:56

I would like to subtract 4 hours from a date. I read the date string into an NSDate object use the following code:

NSDateFormatter * dateFormatter = [[[NSDat         


        
相关标签:
7条回答
  • 2020-12-09 15:58

    NSCalendar is the general API for changing dates based on human time units. For this, you can use NSCalendar's -dateByAddingComponents:toDate:options: with a negative number of hours.

    0 讨论(0)
提交回复
热议问题