2017-06-13 119 views
1

我可以更改当天的突出显示(用红色圈出)。这是当天显示系统,但我的应用程序工作在不同的时区,所以我如何取消突出显示当天或将其更改为另一天。更改日期选择器对话框当前日期 - android java

enter image description here

private void setDateTimeField() { 
    billDate.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      billDateDialog.show(); 
      billDateDialog.updateDate(billDateCal.get(Calendar.YEAR), billDateCal.get(Calendar.MONTH), billDateCal.get(Calendar.DAY_OF_MONTH)); 
     } 
    }); 


    billDateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { 

     public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 

      // Bills need to be set to 00.00 hours. DST needs to be ignored because changing to other timezones with no DST will cause problems with days changing to the day before. 
      long correctedTime = new DayLightSavings(year, monthOfYear, dayOfMonth, timeZone).getCorrectedTime(); 
      billDateCal.setTimeInMillis(correctedTime); 
      billDate.setText(dateFormatter.format(billDateCal.getTimeInMillis())); 
     } 

    },billDateCal.get(Calendar.YEAR), billDateCal.get(Calendar.MONTH), billDateCal.get(Calendar.DAY_OF_MONTH)); 

    // Do not allow selection of <= today's date. 
    // TODO Dialogue needs to be based on timezone selection. 
    long oneDay = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS); 

    long oldRawOffset = TimeZone.getDefault().getRawOffset(); 
    long newRawOffset = timeZone.getRawOffset(); 
    long rawOffset = oldRawOffset - newRawOffset; 
    // TODO fix dialogue to display the correct timezone current day. 
    billDateDialog.getDatePicker().setMinDate(Calendar.getInstance().getTimeInMillis() + oneDay - rawOffset); 
} 
+0

什么是当前良好的应用程序时间? – jeorfevre

+0

这可能有帮助 https://stackoverflow.com/questions/26310750/how-to-set-a-specific-date-in-date-picker-in-android –

+0

好的应用程序时间是第14日 – Mazz

回答

0

你需要做的是显示您的对话框初始化与应用程序很好的日期对话框之前。此代码来自android应用程序。

DatePicker datePicker = (DatePicker) billDateDialog.getDatePicker(); 
TimePicker timePicker = (TimePicker) findViewById(R.id.timepicker); 

DateTime apptime = DateTime.now() ; //From your app, db or other 
int y = apptime.getYear() ; 
int m = apptime.getMonthOfYear() - 1;  // Need to subtract 1 here. 
int d  = apptime.getDayOfMonth(); 
int h = apptime.getHourOfDay(); 
int min = apptime.getMinuteOfHour(); 

//setters 
datePicker.updateDate(y, m, d);    
timePicker.setCurrentHour(h);      
timePicker.setCurrentMinute(min); 
+0

这只更新选定的日期,而不是突出显示的日期以红色 – Mazz

相关问题