Here you can find the source of getQuarterToYearMonthDay(Integer year, Integer quarter)
Parameter | Description |
---|---|
year | a parameter |
quarter | a parameter |
Parameter | Description |
---|
public static Map<String, String> getQuarterToYearMonthDay(Integer year, Integer quarter)
//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; } }