java日期工具類——獲取前一天的日期(不包括週六日)獲取前一天的工作日日期

直接上代碼:

/**
     * 獲取前一天的工作日日期
     * @return
     */
    public static String getPreDay(){
        Calendar now = Calendar.getInstance();
        int today = now.getTime().getDay();//取得今天的星期值
        if(today == now.getFirstDayOfWeek()){//今天在這個星期中是否爲第一天
            now.roll(Calendar.DAY_OF_YEAR, -3);
        }else{
            now.roll(Calendar.DAY_OF_YEAR, -1);
        }
        String year = now.get(Calendar.YEAR) + "";
        String month = (now.get(Calendar.MONTH) + 1)+"";
        String day = now.get(Calendar.DATE) + "";
        if(month.length() == 1){
            month = "0"+month;
        }
        if(day.length()==1){
            day = "0"+day;
        }
        return year + month + day ;
    }

 

不喜勿噴,歡迎各位大佬提建議幫我改進 (* ̄︶ ̄)

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章