几小时之间的操作 [英] Operation between hours

查看:91
本文介绍了几小时之间的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个按钮,当我点击每个按钮时,时间戳出来并在按钮中返回时间。我有2个文本字段和1个标签。在textfield 1中,我将一个数字减去按钮1中的时间减去按钮2中的时间之间的差值。

I have 2 buttons, when I click each button a timepicker comes out and return the time in the button. I have 2 text field and 1 label. In textfield 1 I put a number that will be subtracted to the difference between the time in button 1 minus the time in button 2.

我的第二个文本字段将有一个数字我会乘以减法的结果。我还有一个会返回结果的标签。例如:

My second text field will have a number that I will multiply by the results of the subtraction. I also have a label that will return the result. For Example:

按钮1我有6:00 pm

按钮2我有8:30 pm

减去它们结果是2.5小时

b $ b在文本字段1我有30分钟

减去30分钟到2.5小时将是2小时

在文本字段2我有3号

乘以3到2小时我会有6.

我想在标签上返回6

in button 1 I have 6:00pm
in button 2 I have 8:30pm
subtracting them the results is 2.5 hours
in text field 1 I have 30 minutes
subtracting 30 minutes to 2.5hours will be 2 hours
in text field 2 I have number 3
multiplying number 3 to 2 hours I will have 6.
I would like to return 6 in the label

我可以解决我有日期选择器返回时间的部分。

I could solve the part where I have the date picker returning the time.

任何人都可以给我一些建议如何解决第二部分?
谢谢!

Can anyone give me some suggestion how to solve the second part? Thank you!

推荐答案

创建具有相同日期部分但时间设置为时间的NSDate对象在按钮中。

Create NSDate objects that have the same date part, but with the time set to the times in the buttons.

要减去日期,请使用

 NSTimeInterval seconds = [date timeIntervalSinceDate:otherDate];

NSTimeInterval只是一个数字,你可以将它相乘。首先乘以 60 * 60 以使其达到数小时。然后乘以乘数按钮上的数字。

NSTimeInterval is just a number, you can multiply it. First multiply by 60*60 to get it to hours. Then multiply it by the number on your multiplier button.

这篇关于几小时之间的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆