public static void main(String[] args) {
System.out.println( getMonthStart());
System.out.println( getNextMonthStart());
System.out.println( getMonthEnd());
}
//月初时间
public static String getMonthStart() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
cal.set(Calendar.DAY_OF_MONTH,1);
return df.format(cal.getTime());
}
下月月初时间
public static String getNextMonthStart() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
cal.add(Calendar.MONTH, 1);
cal.set(Calendar.DAY_OF_MONTH,1);
return df.format(cal.getTime());
}
月末时间
public static String getMonthEnd() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
cal.add(Calendar.MONTH, 1);
cal.set(Calendar.DAY_OF_MONTH,0);
return df.format(cal.getTime());
}
//周一
public static String getMonday(int i) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
cal.add(Calendar.DATE, -i*7);
cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
return df.format(cal.getTime());
}
//周末
public static String getSunday(int i) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
cal.add(Calendar.DATE, (-i+1)*7);
cal.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);
return df.format(cal.getTime());
}