当天
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = new Date(System.currentTimeMillis());
String beginData = simpleDateFormat.format(date);
System.out.println("今天时间为:" + beginData);
本周的第一天和最后一天
String firstDay, lastDay, curWeek;
Calendar curStartCal = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
SimpleDateFormat dfWeek = new SimpleDateFormat("(第ww周)");
Calendar cal = (Calendar) curStartCal.clone();
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
firstDay = df.format(cal.getTime());
curWeek = dfWeek.format(cal.getTime());
cal.add(Calendar.DATE, 6);
lastDay = df.format(cal.getTime());
System.out.println("本周周一和周末:" + firstDay + " and " + lastDay + " and "+ curWeek);
本月的第一天和最后一天
String firstDay2, lastDay2;
Calendar curStartCal = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal2 = (Calendar) curStartCal.clone();
cal2.set(Calendar.DAY_OF_MONTH, cal2.getActualMinimum(Calendar.DAY_OF_MONTH));
firstDay2 = format.format(cal2.getTime());
cal2.set(Calendar.DAY_OF_MONTH, cal2.getActualMaximum(Calendar.DAY_OF_MONTH));
lastDay2 = format.format(cal2.getTime());
System.out.println("本月第一天和最后一天分别是:" + firstDay2 + " and " + lastDay2);