我正在使用java和apche poi excel文件在我的DTR项目中工作。下面的if else语句不起作用。如果时间小于12,则必须在单元格1中,如果不是,则必须在单元格3中。但它不会执行必须执行的操作。如果时间> = 12,它仍然在单元格1中。请帮助。谢谢。
Calendar calendar = new GregorianCalendar();
int month = calendar.get(Calendar.MONTH);
String IDnumF = (String) IDnum.getText();
FileInputStream file = new FileInputStream(new File("C:\\Database\\"+IDnumF+".xls"));
HSSFWorkbook wb = new HSSFWorkbook(file);;
Sheet sheet1 = wb.getSheetAt(month);
Cell cell = null;
Date date = new Date();
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
int day=dayOfMonth+7;
Row row = sheet1.getRow(day);
if(Calendar.HOUR_OF_DAY<12)//This code works
{
cell = row.createCell(1);
cell.setCellValue(""+ calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE));
}
else {//this part doesn't..
cell = row.createCell(3);
cell.setCellValue(""+ calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE));
}
答案 0 :(得分:0)
你的问题就在这一行:
if(Calendar.HOUR_OF_DAY<12)
Calendar.HOUR_OF_DAY
的值(注意大C)是一个常量,用于获取日历值的小时部分
根据您的其余代码,我认为您想要的是:
if (calendar.get(Calendar.HOUR_OF_DAY) <12)
这将从您的日历实例中获取当天的小时