[英]Time compare with time picker for android
i want between Asettingtime and Bsettingtime in current time 我想在当前时间在Asettingtime和Bsettingtime之间
how can i compare i change my timepicker? 我如何比较我更改我的时间选择器? what is best plan?
什么是最佳计划? use calender compare DATA value?
使用日历比较DATA值?
dpd=new TimePickerDialog(SettingActivity.this,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view,
int hourOfDay, int minute) {
Toast.makeText(getApplicationContext(),
hourOfDay +"시 " + minute+"분 을 선택했습니다",
Toast.LENGTH_SHORT).show();
String sHour;
if(hourOfDay < 10){
sHour = "0"+hourOfDay;
} else {
sHour = String.valueOf(hourOfDay);
}
int sTime;
String sMinute = "00";
if(minute < 10){
sMinute = "0"+minute;
} else {
sMinute = String.valueOf(minute);
}
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date strDate = sdf.parse(date2);
if (yourdate1 > strDate.getTime()) {
}
You can use the Calendar Object for setting the values that you recive from the TimePicker and the convert them to Date Object: 您可以使用日历对象设置从TimePicker接收的值,并将其转换为日期对象:
Calendar calendar1 = Calendar.getInstance();
calendar1.set(Calendar.YEAR, year);
calendar1.set(Calendar.MONTH, month);
calendar1.set(Calendar.DAY_OF_MONTH, day);
calendar1.set(Calendar.HOUR_OF_DAY, hour);
calendar1.set(Calendar.MINUTE, minute);
Date date = new Date(calendar1.getTimeInMillis());
Calendar calendar2 = Calendar.getInstance();
calendar2.set(Calendar.YEAR, year);
calendar2.set(Calendar.MONTH, month);
calendar2.set(Calendar.DAY_OF_MONTH, day);
calendar2.set(Calendar.HOUR_OF_DAY, hour);
calendar2.set(Calendar.MINUTE, minute);
Date date2 = new Date(calendar2.getTimeInMillis());
And then make comparisions: 然后进行比较:
date1.after(date2);
//or
date1.before(date2);
//or
date1.compareTo(date2);
If you want intervall diferences see this : 如果你想INTERVALL个体差异看这个 :
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.