[英]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. 我有几个小时和几分钟,并且我希望减少1秒的时间。 So, I think I must create a nsdate object with my time, and after find the method to decrease the time. 因此,我认为我必须用自己的时间创建一个nsdate对象,然后找到减少时间的方法。 I looked in the apple documentation but I don't find how to do this. 我查看了Apple文档,但找不到如何执行此操作。
You can use this 你可以用这个
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy"];
NewDateString = [formatter stringFromDate:[NSDate dateWithTimeIntervalSinceNow:-1]
You want NSDateComponents . 您需要NSDateComponents 。 Note, you need to use it with a specific calendar. 请注意,您需要将其用于特定的日历。 A code example is listed on the page to which I linked. 我链接到的页面上列出了一个代码示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.