NSDate 减法麻烦
所以在我的应用程序中我想减去两个日期。第一个日期是设置日期,第二个日期是当前日期。所以我尝试了这段代码:
NSString *setDateString = [NSString stringWithFormat:@"12:30"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDate *setDate = [dateFormatter dateFromString:setDateString];
NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:setDate];
但它计算的是从 1970 年开始的间隔。但我需要从当天开始。有人可以帮忙吗?
so in my app I want to subtract two dates. The first date is set date and the second one is the current date. So i tried this code:
NSString *setDateString = [NSString stringWithFormat:@"12:30"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDate *setDate = [dateFormatter dateFromString:setDateString];
NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:setDate];
But it counts the interval from 1970. But I need from the current day. Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您想要现在与今天 1230 点之间的差异。这可以通过
它不适合你的原因是你没有给出正确的格式来完成。或者,您可以通过指定所有组件而不仅仅是小时和分钟,在
setDateString
中正确描述它。I assume you want the difference between now and 1230 hrs of today. This can be done by
The reason it doesn't work for you is you've not given the format correctly. Alternatively, you can describe it correctly in
setDateString
by specifying all the components rather than just hour and minute.