如何使用java显示每月日期明智的计算?

时间:2017-04-04 08:09:57

标签: java collections java-date

如何使用java显示月度日期明智报告?

这是我的数据。我想根据这些数据计算月度报告。

"days" : [
        {
            "date" : "08-Jan-2017,
            "status" : "WORKINGDAY"
        },
        {
            "date" : "23-Jan-2017,
            "status" : "WORKINGDAY"
        },
        {
            "date" : "09-Feb-2017,
            "status" : "WORKINGDAY"
        },
        {
            "date" : "28-Mar-2017,
            "status" : "WORKINGDAY"
        },
        {
            "date" : "01-Apr-2017,
            "status" : "WORKINGDAY"
        },
        {
            "date" : "12-Apr-2017,
            "status" : "WORKINGDAY"
        },
        {
            "date" : "24-Apr-2017,
            "status" : "WORKINGDAY"
        }
    ]

我的预期输出是

Month         Used WorkingDay      UnUsed Working Day
=====          ==============     ================= 

Jan 2017              2              0  
Feb 2017              1              0
Mar 2017              1              0
Apr 2017              1              2

如何获得此输出我尝试了很多,但我输错了。今天的重要事情是2017年4月4日也考虑

SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
Date start = sdf.parse(convertDateFormat(eachWorkingDays.getDate()));
Date end = sdf.parse(todaysDate());
if (start.before(end) || start.equals(end)) {
    usedWorkingDays++;
    SimpleDateFormat sdf1 = new SimpleDateFormat("MMM-yyyy");
    Date start1 = sdf1.parse(convertDateFormat(eachWorkingDays.getDate()));
    //Date end1 = sdf.parse(todaysDate());
    if (semDurationDetails.contains(sdf1.format(start1))) {
        usedMonths.put(sdf1.format(start1), 1);
        if (usedMonths.get(sdf1.format(start1)) == null) {
            usedMonths.put(sdf1.format(start1), 1);
        }
        else 
            usedMonths.put(sdf1.format(start1), usedMonths.get(sdf1.format(start1) + 1));
    }
} else if (start.after(end)) {
    remainingWorkingDays++;
    SimpleDateFormat sdf1 = new SimpleDateFormat("MMM-yyyy");
    Date start1 = sdf1.parse(convertDateFormat(eachWorkingDays.getDate()));
    //Date end1 = sdf.parse(todaysDate());
    if (semDurationDetails.contains(sdf1.format(start1))) {
        unUsedMonths.put(sdf1.format(start1), 1);
        if (unUsedMonths.get(sdf1.format(start1)) == null)
            unUsedMonths.put(sdf1.format(start1), 1);
        else 
            unUsedMonths.put(sdf1.format(start1), unUsedMonths.get(sdf1.format(start1) + 1));
    }
}


private String convertDateFormat(entity.document.nondbdocument.Date date) throws ParseException {
    entity.document.nondbdocument.Date semEndDate = date;
    DateFormat outputFormat = new SimpleDateFormat("dd-MMM-yyyy");
    DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
    Date endDate = inputFormat.parse(semEndDate.get$date());
    String toDate = outputFormat.format(endDate);
    toDate = decrementDate(toDate);
    return toDate;
}

请帮我找一个解决方案。谢谢

0 个答案:

没有答案