/**
* 选择日期
*/
private void selectDate() {
// 2013年9月3日 14:44
LayoutInflater inflater = LayoutInflater.from(this);
final View timepickerview = inflater.inflate(R.layout.timepicker, null);
ScreenInfo screenInfo = new ScreenInfo(this);
final ExpandWheelMain wheelMain = new ExpandWheelMain(timepickerview,
true);// 时间选择器(日期时间都显示)
wheelMain.screenheight = screenInfo.getHeight(); // 活的设备屏幕高
String time = tvCommissionEndDate.getText().toString(); // 获取界面设置的时间
Calendar calendar = Calendar.getInstance();
if (JudgeDate.isDate(time, "yyyy-MM-dd HH:mm")) { // 判断日期是否合法
try {
calendar.setTime(dateFormat.parse(time));
// calendar.add(Calendar.HOUR_OF_DAY, 1);
} catch (ParseException e) {
e.printStackTrace();
}
}
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int min = calendar.get(Calendar.MINUTE);
wheelMain.initDateTimePicker(year, month, day, hour, min);
new AlertDialog.Builder(this).setTitle("选择时间").setView(timepickerview)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// try {
// if (DateUtil.contrastDate(wheelMain.getTime(),
// mCurDateStr, dateFormat)) {
// tvCommissionEndDate.setText(wheelMain.getTime());
// } else {
// Toast.makeText(
// OptionWriteTradeInfoActivity.this,
// "委托截止时刻要大于或等于当前时间30分钟,小于或等于当前时间7天。",
// Toast.LENGTH_LONG).show();
// }
// } catch (ParseException e) {
// e.printStackTrace();
// } // 设置时间
if (compareDate(wheelMain.getTime().replace("-", ""))) {
tvCommissionEndDate.setText(wheelMain.getTime());
} else {
openToast("委托到期日要小于产品到期日");
}
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).show();
}
-------------------JudgeDate
import java.text.SimpleDateFormat;
public class JudgeDate {
/**
* �ж��Ƿ�Ϊ�Ϸ�������ʱ���ַ���
* @param str_input
* @param str_input
* @return boolean;����Ϊtrue,������Ϊfalse
*/
public static boolean isDate(String str_input,String rDateFormat){
if (!isNull(str_input)) {
SimpleDateFormat formatter = new SimpleDateFormat(rDateFormat);
formatter.setLenient(false);
try {
formatter.format(formatter.parse(str_input));
} catch (Exception e) {
return false;
}
return true;
}
return false;
}
public static boolean isNull(String str){
if(str==null)
return true;
else
return false;
}
}
* 选择日期
*/
private void selectDate() {
// 2013年9月3日 14:44
LayoutInflater inflater = LayoutInflater.from(this);
final View timepickerview = inflater.inflate(R.layout.timepicker, null);
ScreenInfo screenInfo = new ScreenInfo(this);
final ExpandWheelMain wheelMain = new ExpandWheelMain(timepickerview,
true);// 时间选择器(日期时间都显示)
wheelMain.screenheight = screenInfo.getHeight(); // 活的设备屏幕高
String time = tvCommissionEndDate.getText().toString(); // 获取界面设置的时间
Calendar calendar = Calendar.getInstance();
if (JudgeDate.isDate(time, "yyyy-MM-dd HH:mm")) { // 判断日期是否合法
try {
calendar.setTime(dateFormat.parse(time));
// calendar.add(Calendar.HOUR_OF_DAY, 1);
} catch (ParseException e) {
e.printStackTrace();
}
}
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int min = calendar.get(Calendar.MINUTE);
wheelMain.initDateTimePicker(year, month, day, hour, min);
new AlertDialog.Builder(this).setTitle("选择时间").setView(timepickerview)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// try {
// if (DateUtil.contrastDate(wheelMain.getTime(),
// mCurDateStr, dateFormat)) {
// tvCommissionEndDate.setText(wheelMain.getTime());
// } else {
// Toast.makeText(
// OptionWriteTradeInfoActivity.this,
// "委托截止时刻要大于或等于当前时间30分钟,小于或等于当前时间7天。",
// Toast.LENGTH_LONG).show();
// }
// } catch (ParseException e) {
// e.printStackTrace();
// } // 设置时间
if (compareDate(wheelMain.getTime().replace("-", ""))) {
tvCommissionEndDate.setText(wheelMain.getTime());
} else {
openToast("委托到期日要小于产品到期日");
}
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).show();
}
-------------------JudgeDate
import java.text.SimpleDateFormat;
public class JudgeDate {
/**
* �ж��Ƿ�Ϊ�Ϸ�������ʱ���ַ���
* @param str_input
* @param str_input
* @return boolean;����Ϊtrue,������Ϊfalse
*/
public static boolean isDate(String str_input,String rDateFormat){
if (!isNull(str_input)) {
SimpleDateFormat formatter = new SimpleDateFormat(rDateFormat);
formatter.setLenient(false);
try {
formatter.format(formatter.parse(str_input));
} catch (Exception e) {
return false;
}
return true;
}
return false;
}
public static boolean isNull(String str){
if(str==null)
return true;
else
return false;
}
}