123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 |
- package com.rf.woodenFish.utils;
- import com.alibaba.fastjson.JSONObject;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.time.LocalDate;
- import java.util.*;
- /**
- * 获取输入公历日期的生肖、天干地支、农历年、农历月、农历日、公历节日、农历节日、24节气等数据
- */
- public class LunarCalendarFestivalUtils {
- //生肖年
- private String animal;
- //干支年
- private String ganZhiYear;
- //农历年
- private String lunarYear;
- //农历月
- private String lunarMonth;
- //农历日
- private String lunarDay;
- //公历节日
- private String solarFestival;
- //农历节日
- private String lunarFestival;
- //节气
- private String lunarTerm;
- /**
- * 获取查询日期的年份生肖
- */
- public String getAnimal() {
- return animal;
- }
- /**
- * 获取查询日期年份的天干地支
- */
- public String getGanZhiYear() {
- return ganZhiYear;
- }
- /**
- * 获取查询日期的农历年份
- */
- public String getLunarYear() {
- return lunarYear;
- }
- /**
- * 获取查询日期的农历月份
- */
- public String getLunarMonth() {
- return lunarMonth;
- }
- /**
- * 获取查询日期的农历日
- */
- public String getLunarDay() {
- return lunarDay;
- }
- /**
- * 获取查询日期的公历节日(不是节日返回空)
- */
- public String getSolarFestival() {
- return solarFestival;
- }
- /**
- * 获取查询日期的农历节日(不是节日返回空)
- */
- public String getLunarFestival() {
- return lunarFestival;
- }
- /**
- * 获取查询日期的节气数据(不是节气返回空)
- */
- public String getLunarTerm() {
- return lunarTerm;
- }
- // 位数从右往左
- // 1-4:表示当年有无闰年,有的话,为闰月的月份,没有的话,为0。
- // 5-16:为除了闰月外的正常月份是大月还是小月,1为30天,0为29天。
- // 注意:从1月到12月对应的是第16位到第5位。
- // 17-20:表示闰月是大月还是小月,仅当存在闰月的情况下有意义。
- // 举例:
- // 1980年的数据是:0x095b0
- // 二进制:0000 1001 0101 1011 0000
- // 表示1980年没有闰月,从1月到12月的天数依次为:30、29、29、30、29、30、29、30、30、29、30、30。
- // 1982年的数据是:0x0a974
- // 0000 1010 0 1001 0111 0100
- // 表示1982年的4月为闰月,即有第二个4月,且是闰小月。
- // 从1月到13月的天数依次为:30、29、30、29、29(闰月)、30、29、29、30、29、30、30、30。
- private static final long[] lunarInfo = new long[]{
- 0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, //1900-1909
- 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977,
- 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970,
- 0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950,
- 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557,
- 0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, //1950-1959
- 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0,
- 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6,
- 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570,
- 0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0,
- 0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, //2000-2009
- 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930,
- 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530,
- 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45,
- 0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0,
- 0x14b63, 0x09370, 0x049f8, 0x04970, 0x064b0, 0x168a6, 0x0ea50, 0x06b20, 0x1a6c4, 0x0aae0, //2050-2059
- 0x0a2e0, 0x0d2e3, 0x0c960, 0x0d557, 0x0d4a0, 0x0da50, 0x05d55, 0x056a0, 0x0a6d0, 0x055d4, //2060-2069
- 0x052d0, 0x0a9b8, 0x0a950, 0x0b4a0, 0x0b6a6, 0x0ad50, 0x055a0, 0x0aba4, 0x0a5b0, 0x052b0, //2070-2079
- 0x0b273, 0x06930, 0x07337, 0x06aa0, 0x0ad50, 0x14b55, 0x04b60, 0x0a570, 0x054e4, 0x0d160, //2080-2089
- 0x0e968, 0x0d520, 0x0daa0, 0x16aa6, 0x056d0, 0x04ae0, 0x0a9d4, 0x0a2d0, 0x0d150, 0x0f252, //2090-2099
- 0x0d520 //2100
- };
- //公历天数
- private static final int[] solarMonths = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- //生肖
- private static final String[] animals = new String[]{"鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"};
- //天干
- private static final String[] tianGan = new String[]{"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"};
- //地支
- private static final String[] diZhi = new String[]{"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"};
- //农历年
- private static final String[] lunarYears = new String[]{"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
- //农历月份
- private static final String[] lunarMonths = new String[]{"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "冬", "腊"};
- //农历数字
- private static final String[] lunarNumber = new String[]{"一", "二", "三", "四", "五", "六", "七", "八", "九", "十"};
- private static final String[] chineseTen = new String[]{"初", "十", "廿", "三"};
- //二十四节气
- private static final String[] solarTerms = new String[]{"小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨",
- "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至"};
- //二十四节气日期偏移度
- private static final double D = 0.2422;
- //定义一个二维数组,第一维数组存储的是20世纪的节气C值,第二维数组存储的是21世纪的节气C值,0到23个,依次代表小寒、大寒、立春、雨水...冬至节气的C值
- private static final double[][] CENTURY_ARRAY = {
- {6.11, 20.84, 4.6295, 19.4599, 6.3826, 21.4155, 5.59, 20.888, 6.318, 21.86, 6.5, 22.2, 7.928, 23.65, 8.35, 23.95, 8.44, 23.822, 9.098, 24.218, 8.218, 23.08, 7.9, 22.6},
- {5.4055, 20.12, 3.87, 18.73, 5.63, 20.646, 4.81, 20.1, 5.52, 21.04, 5.678, 21.37, 7.108, 22.83, 7.5, 23.13, 7.646, 23.042, 8.318, 23.438, 7.438, 22.36, 7.18, 21.94}
- };
- //特殊年份节气日期偏移
- private static final Map<Integer, Integer[]> INCREASE_OFFSETMAP = new HashMap<>();//+1偏移
- private static final Map<Integer, Integer[]> DECREASE_OFFSETMAP = new HashMap<>();//-1偏移
- static {
- INCREASE_OFFSETMAP.put(0, new Integer[]{1982});//小寒
- DECREASE_OFFSETMAP.put(0, new Integer[]{2019});//小寒
- INCREASE_OFFSETMAP.put(1, new Integer[]{2000, 2082});//大寒
- DECREASE_OFFSETMAP.put(3, new Integer[]{2026});//雨水
- INCREASE_OFFSETMAP.put(5, new Integer[]{2084});//春分
- INCREASE_OFFSETMAP.put(8, new Integer[]{1911});//立夏
- INCREASE_OFFSETMAP.put(9, new Integer[]{2008});//小满
- INCREASE_OFFSETMAP.put(10, new Integer[]{1902});//芒种
- INCREASE_OFFSETMAP.put(11, new Integer[]{1928});//夏至
- INCREASE_OFFSETMAP.put(12, new Integer[]{1925, 2016});//小暑
- INCREASE_OFFSETMAP.put(13, new Integer[]{1922});//大暑
- INCREASE_OFFSETMAP.put(14, new Integer[]{2002});//立秋
- INCREASE_OFFSETMAP.put(16, new Integer[]{1927});//白露
- INCREASE_OFFSETMAP.put(17, new Integer[]{1942});//秋分
- INCREASE_OFFSETMAP.put(19, new Integer[]{2089});//霜降
- INCREASE_OFFSETMAP.put(20, new Integer[]{2089});//立冬
- INCREASE_OFFSETMAP.put(21, new Integer[]{1978});//小雪
- INCREASE_OFFSETMAP.put(22, new Integer[]{1954});//大雪
- DECREASE_OFFSETMAP.put(23, new Integer[]{1918, 2021});//冬至
- }
- //农历节日
- private static final String[] lunarHoliday = new String[]{"0101 春节", "0115 元宵节", "0202 龙抬头", "0303 上巳节", "0505 端午节", "0707 七夕节", "0715 中元节",
- "0815 中秋节", "0909 重阳节", "1001 寒衣节", "1015 下元节", "1208 腊八节", "1223 北小年", "1224 南小年"};
- //公历节日
- private static final String[] solarHoliday = new String[]{
- "0101 元旦", "0110 中国人民警察节", "0214 情人节", "0305 学雷锋纪念日", "0308 妇女节", "0312 植树节", "0315 消费者权益日",
- "0422 地球日", "0423 读书日", "0501 劳动节", "0504 青年节", "0512 护士节", "0518 博物馆日", "0601 儿童节", "0605 环保日",
- "0701 建党节", "0707 七七事变纪念日", "0801 建军节", "0819 中国医师节", "0903 抗日战争胜利纪念日", "0910 教师节", "0918 九一八事变纪念日", "0930 烈士纪念日",
- "1001 国庆节", "1024 联合国日", "1108 记者节", "1204 宪法日", "1213 国家公祭日", "1220 澳门回归纪念日", "1224 平安夜", "1225 圣诞节"
- };
- //格式化日期
- private final SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy年MM月dd日", Locale.CHINA);
- private final SimpleDateFormat solarDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
- /**
- * 返回农历y年的总天数
- */
- private int lunarYearDays(int y) {
- int i, sum = 348;
- for (i = 0x8000; i > 0x8; i >>= 1) {
- sum += ((lunarInfo[y - 1900] & i) != 0 ? 1 : 0);
- }
- return (sum + leapDays(y));
- }
- /**
- * 返回农历y年m月的总天数
- */
- private int monthDays(int y, int m) {
- return ((lunarInfo[y - 1900] & (0x10000 >> m)) != 0 ? 30 : 29);
- }
- /**
- * 返回农历y年闰月的天数
- */
- private int leapDays(int y) {
- if (leapMonth(y) != 0) {
- return ((lunarInfo[y - 1900] & 0x10000) != 0 ? 30 : 29);
- } else
- return 0;
- }
- /**
- * 判断y年的农历中那个月是闰月,不是闰月返回0
- */
- private int leapMonth(int y) {
- return (int) (lunarInfo[y - 1900] & 0xf);
- }
- /**
- * 获取农历年
- */
- private String getLunarYearString(String year) {
- int y1 = Integer.parseInt(year.charAt(0) + "");
- int y2 = Integer.parseInt(year.charAt(1) + "");
- int y3 = Integer.parseInt(year.charAt(2) + "");
- int y4 = Integer.parseInt(year.charAt(3) + "");
- return lunarYears[y1] + lunarYears[y2] + lunarYears[y3] + lunarYears[y4];
- }
- /**
- * 获取农历日
- */
- private String getLunarDayString(int day) {
- if (day > 30)
- return "";
- int n = day % 10 == 0 ? 9 : day % 10 - 1;
- if (day == 10) {
- return "初十";
- } else if (day == 20) {
- return "二十";
- } else {
- return chineseTen[day / 10] + lunarNumber[n];
- }
- }
- /**
- * 特例,特殊的年份的节气偏移量,由于公式并不完善,所以算出的个别节气的第几天数并不准确,在此返回其偏移量
- *
- * @param year 年份
- * @param n 节气编号
- * @return 返回其偏移量
- */
- private int specialYearOffset(int year, int n) {
- int offset = 0;
- offset += getOffset(DECREASE_OFFSETMAP, year, n, -1);
- offset += getOffset(INCREASE_OFFSETMAP, year, n, 1);
- return offset;
- }
- /**
- * 节气偏移量计算
- */
- private int getOffset(Map<Integer, Integer[]> map, int year, int n, int offset) {
- int off = 0;
- Integer[] years = map.get(n);
- if (null != years) {
- for (int i : years) {
- if (i == year) {
- off = offset;
- break;
- }
- }
- }
- return off;
- }
- /**
- * 获取某年的第n个节气为几日(从0小寒起算)
- */
- private int sTerm(int year, int n) {
- int centuryIndex;
- if (year >= 1901 && year < 2000) {//20世纪
- centuryIndex = 0;
- } else if (year == 2000) {//20或21世纪
- if (n < 4) {
- centuryIndex = 0;
- } else {
- centuryIndex = 1;
- }
- } else if (year >= 2001 && year < 2100) {//21世纪
- centuryIndex = 1;
- } else {
- // throw new RuntimeException("不支持此年份:" + year + ",目前只支持1901年到2100年的时间范围");
- return -1;
- }
- double centuryValue = CENTURY_ARRAY[centuryIndex][n];//节气的世纪值,每个节气的每个世纪值都不同
- int Y = year % 100;//步骤1,取年份的后两位数
- int L = Y / 4;//步骤2,闰年数
- if (n < 4) {
- //L:L=Y/4,小寒、大寒、立春、雨水的L=(Y-1)/4
- L = (Y - 1) / 4;
- }
- int dateNum = (int) (Y * D + centuryValue) - L;//步骤3,计算通式寿星公式=[Y*D+C]-L
- dateNum += specialYearOffset(year, n);//步骤4,加上特殊的年份的节气偏移量
- return dateNum;
- }
- /**
- * 母亲节和父亲节
- */
- private String getMotherOrFatherDay(int year, int month, int day) {
- if (month != 5 && month != 6) return null;
- if ((month == 5 && (day < 8 || day > 14)) || (month == 6 && (day < 15 || day > 21))) return null;
- Calendar calendar = Calendar.getInstance();
- calendar.set(year, month - 1, 1);
- int weekDate = calendar.get(Calendar.DAY_OF_WEEK);
- weekDate = (weekDate == 1) ? 7 : weekDate - 1;
- switch (month) {
- case 5:
- if (day == 15 - weekDate) {
- return "母亲节";
- }
- break;
- case 6:
- if (day == 22 - weekDate) {
- return "父亲节";
- }
- break;
- }
- return null;
- }
- /**
- * 感恩节
- */
- private String thanksgiving(int year, int month, int day) {
- if (month != 11) return null;
- if ((month == 11 && (day < 19 || day > 28))) return null;
- Calendar calendar = Calendar.getInstance();
- calendar.set(year, month - 1, 1);
- int weekDate = calendar.get(Calendar.DAY_OF_WEEK);
- weekDate = (weekDate == 1) ? 7 : weekDate - 1;
- switch (month) {
- case 11:
- if (day == 29 - weekDate + 4) {
- return "感恩节";
- }
- break;
- }
- return null;
- }
- /**
- * 输入公历日期初始化当前日期的生肖、天干地支、农历年、农历月、农历日、公历节日、农历节日、24节气
- * 输入日期的格式为(YYYY-MM-DD)
- */
- public void initLunarCalendarInfo(String currentDate) {
- //基准日期
- Date baseDate = null;
- //当前日期
- Date nowDay = null;
- try {
- baseDate = chineseDateFormat.parse("1900年1月31日");//春节
- nowDay = solarDateFormat.parse(currentDate);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- // 获取当前日期与1900年1月31日相差的天数
- int offset = (int) ((nowDay.getTime() - baseDate.getTime()) / 86400000L);
- //用offset减去每农历年的天数,计算当天是农历第几天,iYear最终结果是农历的年份
- int iYear;
- int daysOfYear = 0;
- for (iYear = 1900; iYear < 10000 && offset > 0; iYear++) {
- daysOfYear = lunarYearDays(iYear);
- offset -= daysOfYear;
- }
- if (offset < 0) {
- offset += daysOfYear;
- iYear--;
- }
- //设置生肖
- this.animal = animals[(iYear - 4) % 12];
- //设置天干地支
- int num = iYear - 1900 + 36;
- this.ganZhiYear = (tianGan[num % 10] + diZhi[num % 12]);
- //设置农历年份
- this.lunarYear = getLunarYearString(iYear + "");
- boolean leap = false;
- int leapMonth = leapMonth(iYear); // 闰哪个月,1-12
- // 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
- int iMonth;
- int daysOfMonth = 0;
- for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) {
- // 闰月
- if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) {
- --iMonth;
- leap = true;
- daysOfMonth = leapDays(iYear);
- } else {
- daysOfMonth = monthDays(iYear, iMonth);
- }
- offset -= daysOfMonth;
- // 解除闰月
- if (leap && iMonth == (leapMonth + 1)) {
- leap = false;
- }
- }
- // offset为0时,并且刚才计算的月份是闰月,要校正
- if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) {
- if (leap) {
- leap = false;
- } else {
- leap = true;
- --iMonth;
- }
- }
- // offset小于0时,也要校正
- if (offset < 0) {
- offset += daysOfMonth;
- --iMonth;
- }
- // 设置对应的农历月份
- this.lunarMonth = lunarMonths[iMonth - 1];
- if (leap) {
- this.lunarMonth = "闰" + this.lunarMonth;
- }
- //设置农历日
- int iDay = offset + 1;
- this.lunarDay = getLunarDayString(iDay);
- String[] splitDate = currentDate.split("-");
- // 公历年月日
- int year = Integer.parseInt(splitDate[0]);
- int month = Integer.parseInt(splitDate[1]);
- int day = Integer.parseInt(splitDate[2]);
- //设置节气
- if (day == sTerm(year, (month - 1) * 2)) {
- this.lunarTerm = solarTerms[(month - 1) * 2];
- } else if (day == sTerm(year, (month - 1) * 2 + 1)) {
- this.lunarTerm = solarTerms[(month - 1) * 2 + 1];
- } else {
- this.lunarTerm = "";
- }
- //设置公历节日
- String solarFestival = "";
- for (int i = 0; i < solarHoliday.length; i++) {
- // 返回公历节假日名称
- String sd = solarHoliday[i].split(" ")[0]; // 节假日的日期
- String sdv = solarHoliday[i].split(" ")[1]; // 节假日的名称
- String currentSM = month + "";
- if (month < 10) {
- currentSM = "0" + month;
- }
- String currentSD = day + "";
- if (day < 10) {
- currentSD = "0" + day;
- }
- String currentSMD = currentSM + currentSD;
- if (sd.trim().equals(currentSMD.trim())) {
- solarFestival = sdv;
- break;
- }
- }
- //判断节日是否是父亲节或母亲节
- String motherOrFatherDay = getMotherOrFatherDay(year, month, day);
- if (motherOrFatherDay != null) {
- solarFestival = motherOrFatherDay;
- }
- //判断节日是否是感恩节
- String thanksgiving = thanksgiving(year, month, day);
- if (thanksgiving != null) {
- solarFestival = thanksgiving;
- }
- this.solarFestival = solarFestival;
- //设置农历节日
- String lunarFestival = "";
- for (int i = 0; i < lunarHoliday.length; i++) {
- //农历闰月节日
- if (leap) {
- break;
- }
- // 返回农历节假日名称
- String ld = lunarHoliday[i].split(" ")[0]; // 节假日的日期
- String ldv = lunarHoliday[i].split(" ")[1]; // 节假日的名称
- String currentLM = iMonth + "";
- if (iMonth < 10) {
- currentLM = "0" + iMonth;
- }
- String currentLD = iDay + "";
- if (iDay < 10) {
- currentLD = "0" + iDay;
- }
- String currentLMD = currentLM + currentLD;
- if (ld.trim().equals(currentLMD.trim())) {
- lunarFestival = ldv;
- break;
- }
- if ("12".equals(currentLM) && iDay == daysOfMonth) { // 除夕夜需要特殊处理
- lunarFestival = "除夕";
- break;
- }
- }
- if ("清明".equals(this.lunarTerm)) {
- lunarFestival = "清明节";
- }
- this.lunarFestival = lunarFestival;
- }
- public static void main(String[] args) {
- LunarCalendarFestivalUtils festival = new LunarCalendarFestivalUtils();
- festival.initLunarCalendarInfo(String.valueOf(LocalDate.now()));
- System.out.println("农历:" + festival.lunarYear + "年 " + festival.lunarMonth + "月" + festival.lunarDay + "日");
- System.out.println(festival.ganZhiYear + "【" + festival.animal + "】年");
- System.out.println("节气:" + festival.lunarTerm);
- System.out.println("农历节日:" + festival.lunarFestival);
- System.out.println("公历节日:" + festival.solarFestival);
- }
- public static JSONObject isSpecialDate() {
- LunarCalendarFestivalUtils festival = new LunarCalendarFestivalUtils();
- festival.initLunarCalendarInfo(String.valueOf(LocalDate.now()));
- JSONObject jsonObject = new JSONObject();
- if (festival.lunarTerm != null && !"".equals(festival.lunarTerm)) {
- jsonObject.put("lunarTerm", festival.lunarTerm);
- }
- if (festival.lunarFestival != null && !"".equals(festival.lunarFestival)) {
- jsonObject.put("lunarFestival", festival.lunarFestival);
- }
- if (festival.solarFestival != null && !"".equals(festival.solarFestival)) {
- jsonObject.put("solarFestival", festival.solarFestival);
- }
- return jsonObject;
- }
- }
|