我正在开发一个简单的销售点系统,并试图生成尽可能多的销售和费用数据统计信息。我想要一种方法来显示本周的销售情况,但是,尽管我浏览了 api 并检查了一些教程,但我真的找不到方法。最后,我决定比较一下今天DAY_OF_WEEK_IN_MONTH
发生的交易DAY_OF_WEEK_IN_MONTH
。例如,如果它们相同,则交易必须与今天在同一周发生,即本周。起初,它似乎有效,但现在又重新考虑了。如果有人向我指出正确的方法,我将不胜感激。
public void getSalesTotalForWeek() throws SQLException {
//getDatesCount() populates a collection(listDates) with dates in which
//transactions took place
getDatesCount();
//sets cal with today's date
Calendar cal = new GregorianCalendar();
for (int i = 0; i < listDates.size(); i++) {
//set c with the date of when the transaction took place
Calendar c = new GregorianCalendar(Integer.parseInt(listDates.get(i).substring(0, 4)),
Integer.parseInt(listDates.get(i).substring(5, 7)), Integer.parseInt(listDates.get(i).substring(8, 10)));
//This is like saying if the day of week in month when the transaction took place
//is the same as that of today, then the transaction
//must have taken place in the same week as today
if(cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == c.get(Calendar.DAY_OF_WEEK_IN_MONTH)){
rst = stmt.executeQuery("SELECT * FROM transaction_history where Time like '"+ listDates.get(i) + "%'");
while (rst.next()) {
weekSalesTotal += rst.getInt(2);
}
}
}
}