Java Calendar 获取本周周一和周日代码

/**
  * 得到本周周一
  *
  * @return yyyy-MM-dd
  */
 public static String getMondayOfThisWeek() {
  Calendar c = Calendar.getInstance();
  int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
  if (day_of_week == 0)
   day_of_week = 7;
  c.add(Calendar.DATE, -day_of_week + 1);
  return df2.format(c.getTime());
 }

 

 /**
  * 得到本周周日
  *
  * @return yyyy-MM-dd
  */
 public static String getSundayOfThisWeek() {
  Calendar c = Calendar.getInstance();
  int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
  if (day_of_week == 0)
   day_of_week = 7;
  c.add(Calendar.DATE, -day_of_week + 7);
  return df2.format(c.getTime());
 }

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页