天干地支
This commit is contained in:
@@ -5,6 +5,8 @@ public class MyCalendar {
|
||||
private int year = 0;
|
||||
private int month = 0;
|
||||
|
||||
private int day =0;
|
||||
|
||||
public void setyear(int year) {
|
||||
this.year = year;
|
||||
}
|
||||
@@ -21,6 +23,14 @@ public class MyCalendar {
|
||||
return month;
|
||||
}
|
||||
|
||||
public int getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
public void setDay(int day) {
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
private int chineseyear;// 农历年份
|
||||
private int chinesemonth;// 农历月份
|
||||
private int chineseday;// 农历日
|
||||
@@ -58,6 +68,18 @@ public class MyCalendar {
|
||||
this.setyear(year);
|
||||
this.setmonth(month);
|
||||
this.getfirstday(day);
|
||||
|
||||
setTgchineseyear(checkLC()?year:year-1);
|
||||
//设置月份
|
||||
if(month==1){
|
||||
setTgchinesemonth(checkMonthJQ()?12:11);
|
||||
} else if (month==2) {
|
||||
setTgchinesemonth(checkMonthJQ()?1:12);
|
||||
}else {
|
||||
setTgchinesemonth(checkMonthJQ()?month-1:month-2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Map<String,Integer> getCT(){
|
||||
@@ -65,9 +87,14 @@ public class MyCalendar {
|
||||
Integer c_month = Integer.valueOf(this.getChinesemonth());
|
||||
Integer c_day = (Integer.valueOf(this.getChineseday()))+1;
|
||||
Map<String, Integer> stringIntegerMap = new HashMap<>();
|
||||
stringIntegerMap.put("year",c_year);
|
||||
stringIntegerMap.put("month",c_month);
|
||||
stringIntegerMap.put("day",c_day);
|
||||
stringIntegerMap.put("c_year",c_year);
|
||||
stringIntegerMap.put("c_month",c_month);
|
||||
stringIntegerMap.put("c_day",c_day);
|
||||
stringIntegerMap.put("tg_year",getTgchineseyear());
|
||||
stringIntegerMap.put("tg_month",getTgchinesemonth());
|
||||
|
||||
|
||||
|
||||
return stringIntegerMap;
|
||||
}
|
||||
|
||||
@@ -189,6 +216,7 @@ public class MyCalendar {
|
||||
|
||||
// 计算当年当月day日所对应的农历:chineseyear,chinesemonth,chineseday
|
||||
public void getfirstday(int day) {
|
||||
setDay(day);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(year, month - 1, day);
|
||||
int leapMonth = 0;
|
||||
@@ -455,7 +483,42 @@ public class MyCalendar {
|
||||
}
|
||||
}
|
||||
int num1 = (int) ((Y * D + C1) - L);
|
||||
if(month<num1){
|
||||
|
||||
if(day<num1){
|
||||
return false;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//判断当月节气是否通过
|
||||
public boolean checkMonthJQ(){
|
||||
double D = 0.2422;
|
||||
// "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨",
|
||||
// "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑",
|
||||
// "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至"
|
||||
// 定义数组,存储的是20世纪和21世纪的节气C值
|
||||
double[] SolarTerms_C_20thcentury = { 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 };
|
||||
double[] SolarTerms_C_21stcentury = { 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 };
|
||||
double[] SolarTerms_C = null;
|
||||
if (year >= 1901 && year <= 2000) {// 20世纪
|
||||
SolarTerms_C = SolarTerms_C_20thcentury;
|
||||
} else if (year >= 2001 && year <= 2100) {// 21世纪
|
||||
SolarTerms_C = SolarTerms_C_21stcentury;
|
||||
}
|
||||
double C1 = SolarTerms_C[(month) * 2 - 1 - 1];
|
||||
int Y = year % 100;
|
||||
int L = (Y) / 4;
|
||||
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
|
||||
// 注意:凡闰年3月1日前闰年数要减一,即:L=[(Y-1)/4],因为小寒、大寒、立春、雨水这两个节气都小于3月1日
|
||||
if (C1 == 5.4055 || C1 == 3.87) {
|
||||
L = (Y - 1) / 4;
|
||||
}
|
||||
}
|
||||
int num1 = (int) ((Y * D + C1) - L);
|
||||
if(day<num1){
|
||||
return false;
|
||||
}else {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user