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