获得日期格式的第一天和最后一天

处理日期格式
获得随机月份的第一天和最后一天,

public static String getFristDayofMonth(String year, String str) {

	String month = str.replace("月", "");
	Calendar cal = Calendar.getInstance();
	cal.set(Calendar.YEAR, Integer.parseInt(year));
	cal.set(Calendar.MONTH, Integer.parseInt(month) - 1);
	int fristday = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
	cal.set(Calendar.DAY_OF_MONTH, fristday);
	SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd");
	String FristDayofMonth = simple.format(cal.getTime());
	return FristDayofMonth;
}

获得日期格式的Day
public static String getWeek(String date) {
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
Date da = new Date();;
try {
da = sdf.parse(date);
} catch (Exception e) {
e.printStackTrace();
}
Calendar cal = Calendar.getInstance();
cal.setTime(da);
int week = cal.get(Calendar.DAY_OF_MONTH);

	return week<8?"+第一周":week<15?"+第二周":week<23?"+第三周":"+第四周";

猜你喜欢

转载自blog.csdn.net/weixin_42283373/article/details/88014517
今日推荐