bug
This commit is contained in:
@@ -25,6 +25,77 @@ public class MyCalendar {
|
||||
private int chinesemonth;// 农历月份
|
||||
private int chineseday;// 农历日
|
||||
private boolean leap;// 判断闰月
|
||||
|
||||
private int tgchineseyear;//天干地支年份
|
||||
|
||||
private int tgchinesemonth;//天干地址月份
|
||||
|
||||
|
||||
public int getTgchineseyear() {
|
||||
return tgchineseyear;
|
||||
}
|
||||
|
||||
public void setTgchineseyear(int tgchineseyear) {
|
||||
this.tgchineseyear = tgchineseyear;
|
||||
}
|
||||
|
||||
public int getTgchinesemonth() {
|
||||
return tgchinesemonth;
|
||||
}
|
||||
|
||||
public void setTgchinesemonth(int tgchinesemonth) {
|
||||
this.tgchinesemonth = tgchinesemonth;
|
||||
}
|
||||
|
||||
public void setDate(Date date){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
Integer year = calendar.get(Calendar.YEAR);
|
||||
int kkk = calendar.get(Calendar.MONTH);
|
||||
|
||||
Integer month = kkk + 1;
|
||||
Integer day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
this.setyear(year);
|
||||
this.setmonth(month);
|
||||
this.getfirstday(day);
|
||||
}
|
||||
|
||||
public Map<String,Integer> getCT(){
|
||||
Integer c_year = Integer.valueOf(this.getChineseyear());
|
||||
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);
|
||||
return stringIntegerMap;
|
||||
}
|
||||
|
||||
|
||||
public int getChineseyear() {
|
||||
return chineseyear;
|
||||
}
|
||||
|
||||
public void setChineseyear(int chineseyear) {
|
||||
this.chineseyear = chineseyear;
|
||||
}
|
||||
|
||||
public int getChinesemonth() {
|
||||
return chinesemonth;
|
||||
}
|
||||
|
||||
public void setChinesemonth(int chinesemonth) {
|
||||
this.chinesemonth = chinesemonth;
|
||||
}
|
||||
|
||||
public int getChineseday() {
|
||||
return chineseday;
|
||||
}
|
||||
|
||||
public void setChineseday(int chineseday) {
|
||||
this.chineseday = chineseday;
|
||||
}
|
||||
|
||||
// 1-4: 表示当年有无闰年,有的话,为闰月的月份,没有的话,为0。
|
||||
// 5-16:为除了闰月外的正常月份是大月还是小月,1为30天,0为29天。
|
||||
// 注意:从1月到12月对应的是第16位到第5位。
|
||||
@@ -174,6 +245,14 @@ public class MyCalendar {
|
||||
}
|
||||
this.chinesemonth = lmonth;
|
||||
this.chineseday = offset;
|
||||
|
||||
//添加天干地支时间校正
|
||||
if(!checkLC()){
|
||||
setTgchineseyear(this.chineseyear-1);
|
||||
}else{
|
||||
setTgchineseyear(this.chineseyear);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 返回日期数组的空数据个数,即1号所在行中有多少个空位置
|
||||
@@ -342,6 +421,48 @@ public class MyCalendar {
|
||||
return days;
|
||||
}
|
||||
|
||||
//判断是否过了立春
|
||||
public boolean checkLC(){
|
||||
int getmonth = getmonth();
|
||||
if(getmonth<2){//立春在2月所以1月立春还没到
|
||||
return false;
|
||||
}
|
||||
if(getmonth>2){//2月以上立春肯定是过了
|
||||
return true;
|
||||
}
|
||||
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(month<num1){
|
||||
return false;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 返回包含节日和节气的农历日期数组
|
||||
public String[] getchineseCalendar_festival_solarterms() {
|
||||
String days[] = getchineseCalendar_festival();
|
||||
|
||||
Reference in New Issue
Block a user