获取本周、本月第一天、最后一天
public static void main(String[] args){
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"),Locale.CHINESE);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
System.out.println("first week date: "+sdf.format(cal.getTime()));
cal.add(Calendar.WEEK_OF_YEAR,1);
cal.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);
System.out.println("last week date:"+sdf.format(cal.getTime()));
cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"),Locale.CHINESE);
cal.set(Calendar.DAY_OF_MONTH,1);
System.out.println("first Month date"+sdf.format(cal.getTime()));
cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"),Locale.CHINESE);
cal.add(Calendar.MONTH,1);
cal.set(Calendar.DAY_OF_MONTH,0);
System.out.println("last Month date:"+sdf.format(cal.getTime()));
}
网友评论