[英]Check if 1st timepicker earlier than 2nd timepicker
I have 2 timepicker which represent start and finish. 我有2个时间选择器,分别代表开始和结束。 It means the start time must be earlier than the finish.
这意味着开始时间必须早于结束时间。
My idea is to use Calendar
class and use getTimeInMillis
to do the validation, but its not working : 我的想法是使用
Calendar
类并使用getTimeInMillis
进行验证,但是它不起作用:
Calendar calFrom = Calendar.getInstance();
Calendar calTo = Calendar.getInstance();
calFrom.set(Calendar.HOUR_OF_DAY, timeSchedule.getCurrentHour());
calFrom.set(Calendar.MINUTE, timeSchedule.getCurrentMinute());
calTo.set(Calendar.HOUR_OF_DAY, toTime.getCurrentHour());
calTo.set(Calendar.MINUTE, toTime.getCurrentMinute());
if(calFrom.getTimeInMillis() > calTo.getTimeInMillis())
{
Crouton.makeText(MyActivity.this, "error", Style.ALERT).show();
}
When i debug the above code, although the timeSchedule
is earlier then toTime
, the value of calFrom.getTimeInMillis()
is bigger than calTo.getTimeInMillis()
. 当我调试上述代码时,尽管
timeSchedule
早于toTime
,但calFrom.getTimeInMillis()
的值大于calTo.getTimeInMillis()
。
Please kindly help me, Thanks for your time. 请帮助我,谢谢您的时间。
int fromHour = calFrom.getCurrentHour();
int toHour = calTo.getCurrentHour();
int fromMin = calFrom.getCurrentMinute();
int toMin= calTo.getCurrentMinute();
if (fromHour >toHour )
{
System.out.println ("from time is greater");
}
else if (fromHour==toHour)
{
if (fromMin>toMin)
{
System.out.println ("from time is greater");
}
else
{
System.out.println ("To time is greater");
}
}
else
{
System.out.println ("To time is greater");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.