1
0
mirror of synced 2026-04-09 18:08:43 +08:00

修复时辰天干计算错误,支持早子时和晚子时

This commit is contained in:
6tail
2020-05-26 23:03:33 +08:00
parent 103e4c9bb9
commit f70654a9be
2 changed files with 131 additions and 99 deletions

View File

@@ -332,8 +332,17 @@ public class Lunar{
* 干支纪时计算
*/
private void computeTime(){
timeZhiIndex = LunarUtil.getTimeZhiIndex((hour<10?"0":"")+hour+":"+(minute<10?"0":"")+minute);
timeGanIndex = timeZhiIndex%10;
String hm = (hour<10?"0":"")+hour+":"+(minute<10?"0":"")+minute;
timeZhiIndex = LunarUtil.getTimeZhiIndex(hm);
int dayGan = dayGanIndex;
// 晚子时(夜子/子夜)应算作第二天
if(hm.compareTo("23:00")>=0&&hm.compareTo("23:59")<=0){
dayGan++;
if(dayGan>=10){
dayGan -= 10;
}
}
timeGanIndex = (dayGan%5*2+timeZhiIndex)%10;
}
/**
@@ -681,7 +690,7 @@ public class Lunar{
}
/**
* 获取时辰干支(时柱)
* 获取时辰干支(时柱),支持早子时和晚子时
* @return 时辰干支(时柱)
*/
public String getTimeInGanZhi(){