选择日期

/**
* 选择日期
*/
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;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值