java获取当前日期所在的周的周一,并以周一为一周开始


public String getMonday(String date) {
      if (date == null || date.equals("")) {
          System.out.println("date is null or empty");
          return "0000-00-00 00:00:00";
      }
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
      Date d = null;
      try  {
          d = format.parse(date);
      }
      catch(Exception e) {
          e.printStackTrace();
      }
      Calendar cal = Calendar.getInstance();
      cal.setTime(d);
      //set the first day of the week is Monday
      cal.setFirstDayOfWeek(Calendar.MONDAY);
      cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
      return format.format(cal.getTime())+ " 00:00:00";
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM