JAVA----计算当天过去占本月时间比

计算当天过去占本月时间比

当前时间:2022-6-7

计算方法

/**
  * 计算时间进度:是否超过当前月
  * @param date
  * @return
  */
 public static String countTimeProgress(String date) {
          
   
     if (!Objects.isNull(date)) {
          
   
         String[] dateStr = date.split("-");

         if (dateStr.length == BaseConstant.TWO) {
          
   
             double val = DateUtils.countTodayPassMonthPercent(Integer.parseInt(dateStr[0]), Integer.parseInt(dateStr[1]));

             if (val > BaseConstant.ZERO) {
          
   
                 return val + BaseConstant.SYMBOL_PERCENT;
             }
         }
     }

     return "0";
 }

工具方法

public static int checkDateHasPassMonth(int year, int month) {
          
   
    return checkDateHasPassDate(dateTime(DateUtils.YYYYMM, year +""+ month), DateUtils.YYYYMM);
}



/**
 * 计算当天过去占本月时间比
 * @return
 */
public static double countTodayPassMonthPercent() {
          
   
    return NumUtils.countPercent(NumUtils.countFourDecimalPercent(Calendar.getInstance().get(Calendar.DAY_OF_MONTH), getDaysOfMonth()));
}

public static double countTodayPassMonthPercent(int year, int month) {
          
   
    int mode = checkDateHasPassMonth(year, month);

    if (mode == BaseConstant.ZERO) {
          
   
        // 已结束
        return 100;
    } else if (mode == BaseConstant.ONE) {
          
   
        // 当前月
        return countTodayPassMonthPercent();
    }

    // 未开始
    return 0;
}
经验分享 程序员 微信小程序 职场和发展