- 获取本周的第一天
public static String getFirstDay0fWeek() {
Calendar calendar = Calendar.getInstance();
//设置该周第一天为星期一
calendar.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
return date2String(calendar.getTime(), null);
}
- 获取本月的第一天
public static String getFirstDay0fMonth() {
Calendar calendar = Calendar.getInstance();
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
calendar.add(Calendar.DAY_OF_MONTH, -dayOfMonth + 1);
return date2String(calendar.getTime(), null);
}
- 获取今年的第一天
public static String getFirstDay0fYear() {
Calendar calendar = Calendar.getInstance();
int dayOfYear = Calendar.getInstance().get(Calendar.DAY_OF_YEAR);
calendar.add(Calendar.DAY_OF_YEAR, -dayOfYear + 1);
return date2String(calendar.getTime(), null);
}