1
0
mirror of synced 2026-10-20 13:36:11 +08:00

v1.2.16 补充灶马头相关内容;修复九星错误;新增太岁方位;新增道历天赦日;修复八字转阳历的错误;优化代码。

This commit is contained in:
6tail
2022-01-02 17:36:12 +08:00
parent c91bcc5da7
commit e010e64f1a
12 changed files with 683 additions and 166 deletions

View File

@@ -1,5 +1,7 @@
package com.nlf.calendar;
import com.nlf.calendar.util.SolarUtil;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
@@ -20,6 +22,9 @@ public class ExactDate {
Calendar c = Calendar.getInstance(TIME_ZONE);
c.set(year, month - 1, day, hour, minute, second);
c.set(Calendar.MILLISECOND, 0);
if (0 == year) {
c.add(Calendar.YEAR, 1);
}
return c;
}
@@ -33,4 +38,50 @@ public class ExactDate {
c.set(Calendar.MILLISECOND, 0);
return c;
}
/**
* 获取两个日期之间相差的天数(如果日期a比日期b小,天数为正,如果日期a比日期b大,天数为负)
*
* @param ay 年a
* @param am 月a
* @param ad 日a
* @param by 年b
* @param bm 月b
* @param bd 日b
* @return 天数
*/
public static int getDaysBetween(int ay, int am, int ad, int by, int bm, int bd) {
int n;
int days;
int i;
if (ay == by) {
n = SolarUtil.getDaysInYear(by, bm, bd) - SolarUtil.getDaysInYear(ay, am, ad);
} else if (ay > by) {
days = SolarUtil.getDaysOfYear(by) - SolarUtil.getDaysInYear(by, bm, bd);
for (i = by + 1; i < ay; i++) {
days += SolarUtil.getDaysOfYear(i);
}
days += SolarUtil.getDaysInYear(ay, am, ad);
n = -days;
} else {
days = SolarUtil.getDaysOfYear(ay) - SolarUtil.getDaysInYear(ay, am, ad);
for (i = ay + 1; i < by; i++) {
days += SolarUtil.getDaysOfYear(i);
}
days += SolarUtil.getDaysInYear(by, bm, bd);
n = days;
}
return n;
}
/**
* 获取两个日期之间相差的天数(如果日期a比日期b小,天数为正,如果日期a比日期b大,天数为负)
*
* @param calendar0 日期a
* @param calendar1 日期b
* @return 天数
*/
public static int getDaysBetween(Calendar calendar0, Calendar calendar1) {
return getDaysBetween(calendar0.get(Calendar.YEAR), calendar0.get(Calendar.MONTH) + 1, calendar0.get(Calendar.DATE), calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH) + 1, calendar1.get(Calendar.DATE));
}
}