如何设置上个月的最短日期26 [英] How to set minimum date to previous month 26
问题描述
如何设置上个月的最短日期26
我尝试了什么:
int minDiffrence = 0;
if(day == 26){
minDiffrence = difference;
} else {
minDiffrence =差异 - (26天);
}
dpd.getDatePicker()。setMinDate (System.currentTimeMillis() - 24 * 60 * 60 * 1000 * minDiffrence);
How to set minimum date to previous month 26
What I have tried:
int minDiffrence = 0;
if (day == 26) {
minDiffrence = difference;
} else {
minDiffrence = difference - (26 - day);
}
dpd.getDatePicker().setMinDate(System.currentTimeMillis() - 24 * 60 * 60 * 1000 * minDiffrence);
推荐答案
我不明白为什么你不会在下面使用这样的东西 - 你的方法看起来很复杂
I dont see why you wouldnt use something like this, below - your method looks 'complicated'
import java.util.Calendar;
// Get Calendar For Today
Calendar calNow = Calendar.getInstance();
// Subtract a month from the Calendar
calNow.add(Calendar.MONTH, -1);
// Set the Calendar Day of Month to 26
calNow.set(Calendar.DAY_OF_MONTH, 26);
//
// Set DatePicker MinDate Value
//
dpd.getDatePicker().setMinDate(calNow.getTimeInMillis());
在日期等方面使用正确的工具总是更好/更合适,它们为你处理月份等等
**免责声明 - 我不是java程序员,所以你需要仔细检查这项工作**
Its always better/more appropriate to use the correct tools where dates etc are concerned, they handle month wrap around etc for you
** Disclaimer - Im NOT a java programmer, so you need to check that work closely **
这篇关于如何设置上个月的最短日期26的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!