我正在尝试获取列出一年中第几周的数据库列的第一天和最后一天。我可以将所有星期都提取到一个列表中,但是我希望将其像月的第一天和最后一天一样列出。例如:我有一年中的“ 39”和“ 40”。我想在列表视图中显示它,例如“ 9月24日-十月30日”和“十月1日-十月7日”。
我使用此查询和SimpleCursorAdapter来显示到列表视图中:
String query = "SELECT _id, semana_ano, SUM(valor_uber) AS valor FROM uber_records GROUP BY semana_ano ORDER BY semana_ano";
Cursor cursor = db.rawQuery(query, null);
cursor.moveToFirst();
Calendar c = Calendar.getInstance();
c.get(Calendar.MONTH);
String[] from = {"week_year", "value"};
int[] to = {R.id.week,R.id.value};
ListAdapter adapter = new SimpleCursorAdapter(ReportWeek.this,
R.layout.report_week,
cursor,from,to);
listview.setAdapter(adapter);
答案 0 :(得分:0)
尝试一下:
void getStartEndOFWeek(int enterWeek, int enterYear){
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(Calendar.WEEK_OF_YEAR, enterWeek);
calendar.set(Calendar.YEAR, enterYear);
SimpleDateFormat formatter = new SimpleDateFormat("dd MMM");
Date startDate = calendar.getTime();
String startDateInStr = formatter.format(startDate);
calendar.add(Calendar.DATE, 6);
Date enddate = calendar.getTime();
String endDaString = formatter.format(enddate);
String getDate = startDateInStr + " - " + endDaString;
}