简体   繁体   中英

Decrease time in objective-c

I have a number of hours and a number of minutes, and I want a reduce the time of 1 second. So, I think I must create a nsdate object with my time, and after find the method to decrease the time. I looked in the apple documentation but I don't find how to do this.

You can use this

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy"];
NewDateString = [formatter stringFromDate:[NSDate dateWithTimeIntervalSinceNow:-1]

You want NSDateComponents . Note, you need to use it with a specific calendar. A code example is listed on the page to which I linked.

Don't reinvent the wheel. There are many open source NSDate additions that you can use here. See here

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM