我正在尝试将DateTime从date4j库转换为Calendar实例或Date实例,任何工作。目前我必须将其转换为Calendar实例的代码是
Calendar Qurancal = Calendar.getInstance();
Qurancal.set(Calendar.DAY_OF_WEEK, dateTime.getWeekDay());
Qurancal.set(Calendar.YEAR, dateTime.getYear());
Qurancal.set(Calendar.MONTH, dateTime.getMonth());
Qurancal.set(Calendar.DAY_OF_YEAR, dateTime.getDayOfYear());
Qurancal.set(Calendar.DAY_OF_MONTH, dateTime.getStartOfDay().getDay());
Qurancal.set(Calendar.HOUR, dateTime.getHour());
Qurancal.set(Calendar.MINUTE, dateTime.getMinute());
Qurancal.set(Calendar.SECOND, dateTime.getSecond());
但这并不完美,因为目前所有日期都显示相差1或2天
答案 0 :(得分:0)
固定
从上面的代码中删除此行修复了所有内容
Qurancal.set(Calendar.DAY_OF_MONTH, dateTime.getStartOfDay().getDay());