Java Year Month getQuarterToYearMonthDay(Integer year, Integer quarter)

Here you can find the source of getQuarterToYearMonthDay(Integer year, Integer quarter)

Description

QuarterToYearMonthDay

License

Open Source License

Parameter

Parameter Description
year a parameter
quarter a parameter

Exception

Parameter Description

Return

Map

Declaration

public static Map<String, String> getQuarterToYearMonthDay(Integer year, Integer quarter) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    /**//from   w  w w.jav a  2 s . c om
     * QuarterToYearMonthDay
     *
     * @param year
     * @param quarter
     * @return Map<String,String>
     * @throws
     * @since 1.0.0
     */
    public static Map<String, String> getQuarterToYearMonthDay(Integer year, Integer quarter) {
        if (year != null && year > 0 && quarter != null && quarter > 0) {
            Map<String, String> map = new HashMap<String, String>();
            if (quarter == 1) {
                map.put("startTime", year + "-01-" + getMonthDays(year, 1) + " 00:00:00");
                map.put("endTime", year + "-03-" + getMonthDays(year, 3) + " 23:59:59");
            } else if (quarter == 2) {
                map.put("startTime", year + "-04-" + getMonthDays(year, 4) + " 00:00:00");
                map.put("endTime", year + "-06-" + getMonthDays(year, 6) + " 23:59:59");
            } else if (quarter == 3) {
                map.put("startTime", year + "-07-" + getMonthDays(year, 7) + " 00:00:00");
                map.put("endTime", year + "-09-" + getMonthDays(year, 9) + " 23:59:59");
            } else if (quarter == 4) {
                map.put("startTime", year + "-10-" + getMonthDays(year, 10) + " 00:00:00");
                map.put("endTime", year + "-12-" + getMonthDays(year, 12) + " 23:59:59");
            }
            return map;
        }
        return null;
    }

    public static Integer getMonthDays(Integer year, Integer month) {
        if (year != null && year > 0 && month != null && month > 0) {
            Calendar c = Calendar.getInstance();
            c.set(Calendar.YEAR, year);
            c.set(Calendar.MONTH, month);
            c.set(Calendar.DATE, 1);
            c.add(Calendar.DATE, -1);
            return c.get(Calendar.DATE);
        }
        return 0;
    }
}

Related

  1. getFirstTimeOfDay(int year, int month, int day)
  2. getFirstYearMonth()
  3. getMonthDays(Integer year, Integer month)
  4. getMonthDays(Integer year, Integer month)
  5. getPerMonthByCuttentYear()
  6. getStartMonth(int year, int month)
  7. getTheLastDayOfTheMonth(int year, int month)
  8. getThisYearMonth()
  9. getThisYearMonth()