欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

初始化一个系统时间选择器

程序员文章站 2022-05-01 17:13:49
...
 /**
     * 获取当前日期
     */
    private void getNowDate(){
        Calendar calendar = Calendar.getInstance();
        nowYear = calendar.get(Calendar.YEAR);
        nowMonth = calendar.get(Calendar.MONTH);
        nowDate = calendar.get(Calendar.DAY_OF_MONTH);
    }


//创建时间选择器 初始 为当前日期
        datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                if (isSetStart){//设置开始时间
                    start_year = year;
                    start_month = monthOfYear + 1;
                    start_date = dayOfMonth;
                    setStartTime.setText(year+getString(R.string.year)+(monthOfYear+1)+getString(R.string.month)+dayOfMonth+getString(R.string.day));
                }else {//设置结束时加
                    stop_year = year;
                    stop_month = monthOfYear + 1;
                    stop_date = dayOfMonth;
                    setStopTime.setText(year+getString(R.string.year)+(monthOfYear+1)+getString(R.string.month)+dayOfMonth+getString(R.string.day));
                }
            }
        },nowYear,nowMonth,nowDate);