gpt4 book ai didi

java - 它始终处于 'else' 状态。 (时间选择器)

转载 作者:行者123 更新时间:2023-11-29 04:16:54 25 4
gpt4 key购买 nike

大家早上好

1) 我正在尝试比较两个时间选择器,但效果不佳。它总是给出相同的选项 - else

int firstHouer =fromTimePicker.getCurrentHour();
int firstdMinute =fromTimePicker.getCurrentMinute();
int seccoundHouer = fromTimePicker.getCurrentHour();
int seccoundMinute =fromTimePicker.getCurrentMinute();

if (firstHouer + firstdMinute < seccoundHouer + seccoundMinute)
{
Toast toast = Toast.makeText(getApplicationContext(), "B" , Toast.LENGTH_LONG);
toast.show();
}
else
{
Toast toast = Toast.makeText(getApplicationContext(), "A" , Toast.LENGTH_LONG);
toast.show();
}

2) 当我放置“:”符号时,我遇到了另一个问题,文本改变了它的方向

pic of the problem

最佳答案

如果要比较相对的 24 小时时间,您应该将小时和分钟部分转换为相同单位,然后进行比较。例如,要使用分钟比较两者:

int firstHouer = fromTimePicker.getHour();     // getCurrentHour() is deprecated
int firstdMinute = fromTimePicker.getMinute(); // getCurrentMinute() is deprecated
int seccoundHouer = toTimePicker.getHour(); // or whatever it is called
int seccoundMinute = toTimePicker.getMinute(); // or whatever it is called

if (60*firstHouer + firstdMinute < 60*seccoundHouer + seccoundMinute) {
Toast toast = Toast.makeText(getApplicationContext(), "B" , Toast.LENGTH_LONG);
toast.show();
}
else {
Toast toast = Toast.makeText(getApplicationContext(), "A" , Toast.LENGTH_LONG);
toast.show();
}

编辑:正如@Dennis 刚刚指出的那样,您的代码中也有拼写错误,并且您对两组时间都使用了相同的 TimePicker,这可能不是您想要的。

关于java - 它始终处于 'else' 状态。 (时间选择器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51779527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com