我设置 calendar.DAY_OF_MONTH 时遇到问题
Got an issue when i set calendar.DAY_OF_MONTH
我想设置一个时间在两个时间范围之间,所以我得到当前时间,设置第一次和第二次比较。
但是我发现DAY_OF_MONTH的值很奇怪。为什么它显示错误的值?
有人可以教我如何解决吗?
// load current time
Calendar current = Calendar.getInstance();
//set first time
Calendar firstLimit= Calendar.getInstance();
firstLimit.set(Calendar.MONTH,4);
firstLimit.set(Calendar.DAY_OF_MONTH,8);
firstLimit.set(Calendar.HOUR, 12);
firstLimit.set(Calendar.MINUTE, 30);
firstLimit.set(Calendar.SECOND, 30);
//set second time
Calendar secondLimit= Calendar.getInstance();
firstLimit.set(Calendar.MONTH,4);
firstLimit.set(Calendar.DAY_OF_MONTH,12);
secondLimit.set(Calendar.HOUR, 12);
secondLimit.set(Calendar.MINUTE, 30);
secondLimit.set(Calendar.SECOND, 30);
//Wed May 10 06:14:04 GMT+00:00 2017
Log.d("MONTH: current>",current.getTime()+"");
//Fri May 12 12:30:30 GMT+00:00 2017 --> i thought it should be May 8
Log.d("MONTH: firstLimit>",firstLimit.getTime()+"");
//Wed May 10 12:30:30 GMT+00:00 2017 --> i thought it should be May 12
Log.d("MONTH: secondLimit>",secondLimit.getTime()+"");
您正在行后设置 firstLimit -> //设置第二次
将 firstLimit 替换为 secondLImit
//set second time
Calendar secondLimit= Calendar.getInstance();
secondLimit.set(Calendar.MONTH,4); //replaced firstLimit with secondLImit
secondLimit.set(Calendar.DAY_OF_MONTH,12); //replaced firstLimit with secondLImit
secondLimit.set(Calendar.HOUR, 12);
secondLimit.set(Calendar.MINUTE, 30);
secondLimit.set(Calendar.SECOND, 30);
我想设置一个时间在两个时间范围之间,所以我得到当前时间,设置第一次和第二次比较。
但是我发现DAY_OF_MONTH的值很奇怪。为什么它显示错误的值? 有人可以教我如何解决吗?
// load current time
Calendar current = Calendar.getInstance();
//set first time
Calendar firstLimit= Calendar.getInstance();
firstLimit.set(Calendar.MONTH,4);
firstLimit.set(Calendar.DAY_OF_MONTH,8);
firstLimit.set(Calendar.HOUR, 12);
firstLimit.set(Calendar.MINUTE, 30);
firstLimit.set(Calendar.SECOND, 30);
//set second time
Calendar secondLimit= Calendar.getInstance();
firstLimit.set(Calendar.MONTH,4);
firstLimit.set(Calendar.DAY_OF_MONTH,12);
secondLimit.set(Calendar.HOUR, 12);
secondLimit.set(Calendar.MINUTE, 30);
secondLimit.set(Calendar.SECOND, 30);
//Wed May 10 06:14:04 GMT+00:00 2017
Log.d("MONTH: current>",current.getTime()+"");
//Fri May 12 12:30:30 GMT+00:00 2017 --> i thought it should be May 8
Log.d("MONTH: firstLimit>",firstLimit.getTime()+"");
//Wed May 10 12:30:30 GMT+00:00 2017 --> i thought it should be May 12
Log.d("MONTH: secondLimit>",secondLimit.getTime()+"");
您正在行后设置 firstLimit -> //设置第二次
将 firstLimit 替换为 secondLImit
//set second time
Calendar secondLimit= Calendar.getInstance();
secondLimit.set(Calendar.MONTH,4); //replaced firstLimit with secondLImit
secondLimit.set(Calendar.DAY_OF_MONTH,12); //replaced firstLimit with secondLImit
secondLimit.set(Calendar.HOUR, 12);
secondLimit.set(Calendar.MINUTE, 30);
secondLimit.set(Calendar.SECOND, 30);