代码拉取完成,页面将自动刷新
package com.quietor.calendar.week;
import com.quietor.calendar.constants.CalendarMonth;
import com.quietor.calendar.exception.CalendarException;
import com.quietor.calendar.tool.CalendarTool;
/**
* @author Quietor
* @create 2018-06-17 19:34
* @desc 根据已知星期的日期计算指定日志的星期
* 利用儒略日(Julian Day,JD)进行星期的推算
* 儒略日是一种不记年,不记月,只记日的历法,是完全基于天数的
* 计算公式
* days = int(1461*(y+4716)/4) + int(153*(m+1)/5) + d + c -1524.5
* y表示为年份
* m月份,如果m小于或等于2,则m修正为m+12,同时年份修正为y-1
* c的取值公式:c = 2 - int(y/100) + int(y/400)
* int表示取整,舍去小数部分
**/
public class CalculateWeekdayWithJulian {
/**
* 根据儒略日公式进行计算儒略日
* @param year
* @param month
* @param day
* @return
* @throws CalendarException
*/
public static int calculateDaysWithJulian(int year, CalendarMonth month, int day) throws CalendarException {
CalendarTool.checkParam(year, month, day);
int monthVal = month.getSort();
if(month.compare(CalendarMonth.FEBRUARY) <= 0) {
monthVal = month.getSort() + 12;
year = year - 1;
}
//计算 c 值
int c = 2 - Integer.valueOf(year/100) + Integer.valueOf(year/400);
day += 0.5000115740;//因为儒略日的开始是从中午12点开始的,所以需要加0.5天, 0.0000115740天=1秒
return (int) (Integer.valueOf(1461 * (year + 4716) / 4) + Integer.valueOf(153 * (monthVal + 1)/5) + day + c - 1514.5);
}
public static void main(String[] args) throws CalendarException {
int end = calculateDaysWithJulian(2005, CalendarMonth.MAY, 31);
int start = calculateDaysWithJulian(1977, CalendarMonth.MARCH, 27);
System.out.println(end - start);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。