android获取本周本月本年的第一天和最后一天


/***
* 获取本周的第一天和最后一天:
*/
public static String getFirstDayAndLastDayOfDay() {
StringBuffer stringBuffer=new StringBuffer();
SimpleDateFormat dateFormater = new SimpleDateFormat(
“yyyy-MM-dd”);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_WEEK, 1);
cal.getTime();
stringBuffer.append(dateFormater.format(cal.getTime()) + “”);
cal.set(Calendar.DAY_OF_WEEK,
cal.getActualMaximum(Calendar.DAY_OF_WEEK));
stringBuffer.append(“-“+dateFormater.format(cal.getTime()));
return stringBuffer.toString();
}
/**
* 获取本月的第一天和最后一天:
* @return
*/
public static String getFirstDayAndLastDayOfMonth() {
StringBuffer stringBuffer=new StringBuffer();
SimpleDateFormat dateFormater = new SimpleDateFormat(
“MM-dd”);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.getTime();
stringBuffer.append(dateFormater.format(cal.getTime()) + “”);
cal.set(Calendar.DAY_OF_MONTH,
cal.getActualMaximum(Calendar.DAY_OF_MONTH));
stringBuffer.append(“-“+dateFormater.format(cal.getTime()));
return stringBuffer.toString();
}
/**
* 获取本年的第一天和最后一天:
*
* @return
*/
public static String getFirstDayAndLastDayOfYear() {
StringBuffer stringBuffer=new StringBuffer();
SimpleDateFormat dateFormater = new SimpleDateFormat(
“yyyy-MM-dd”);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_YEAR, 1);
cal.getTime();
stringBuffer.append(dateFormater.format(cal.getTime()) + “”);
cal.set(Calendar.DAY_OF_YEAR,
cal.getActualMaximum(Calendar.DAY_OF_YEAR));
stringBuffer.append(“-“+dateFormater.format(cal.getTime()));
return stringBuffer.toString();
}

标签

发表评论

评论列表(1)