資源簡介
說明:
1. LunarCalendar對象是以月歷為基準的,例如:2014年8月的月歷數(shù)據(jù)。
2. LunarCalendar的所有方法都是針對于農(nóng)歷而言,例如getMonth方法,代表獲取的是農(nóng)歷月的數(shù)據(jù),而不是公歷。
3. LunarCalendar實例化,默認為今天,可以指定為某天,大多數(shù)方法都是依據(jù)實例化時指定的天而返回數(shù)據(jù)的。
4. LunarDate類,是某一天的農(nóng)歷數(shù)據(jù)對象,并且已經(jīng)拆分,而不是以前那樣都混雜在一塊。
5. JulianDate類,是公歷數(shù)據(jù)對象。
6. LunarConstant類,是基本常量的數(shù)據(jù)對象,里面含有大量基本數(shù)據(jù)。
本次的封裝版,實質(zhì)上還是較為簡單,沒有進一步深入和挖掘,但也基本夠用了。各位讀者可以根據(jù)自己的需要進行進一步整理,不過再整理和改造之前,建議還是先了解下相關(guān)的知識,否則估計你都無從下手,即便改了,在不了解邏輯的情況下,也容易出錯。

代碼片段和文件信息
package?com.util;
import?com.util.LunarConstant.Common;
public?class?JulianDate?{
/**?所在公歷年?*/
private?int?year?=?2000;
/**?所在公歷月?*/
private?int?month?=?1;
/**?所在公歷日?*/
private?int?day?=?1;
/**?所在公歷小時?*/
private?int?hour?=?12;
/**?所在公歷分鐘?*/
private?int?minute?=?0;
/**?所在公歷秒鐘?*/
private?double?second?=?0;
// private?final?String[]?weeks?=?{?“日“?“一“?“二“?“三“?“四“?“五“?“六“?“七“?};
public?int?getYear()?{
return?year;
}
public?void?setYear(int?year)?{
this.year?=?year;
}
public?int?getMonth()?{
return?month;
}
public?void?setMonth(int?month)?{
this.month?=?month;
}
public?int?getDay()?{
return?day;
}
public?void?setDay(int?day)?{
this.day?=?day;
}
public?int?getHour()?{
return?hour;
}
public?void?setHour(int?hour)?{
this.hour?=?hour;
}
public?int?getMinute()?{
return?minute;
}
public?void?setMinute(int?minute)?{
this.minute?=?minute;
}
public?double?getSecond()?{
return?second;
}
public?void?setSecond(double?second)?{
this.second?=?second;
}
//?公歷轉(zhuǎn)儒略日
private?double?JD(int?year?int?month?double?day)?{
int?n?=?0?G?=?0;
if?(year?*?372?+?month?*?31?+?Math.floor(day)?>=?588829)
G?=?1;?//?判斷是否為格里高利歷日1582*372+10*31+15
if?(month?<=?2)?{
month?+=?12;
year--;
}
if?(G?!=?0)?{
n?=?(int)?Math.floor(year?/?100);
n?=?2?-?n?+?(int)?Math.floor(n?/?4);?//?加百年閏
}
return?Math.floor(365.25?*?(year?+?4716))?+?Math.floor(30.6001?*?(month?+?1))?+?day?+?n?-?1524.5;
}
//?儒略日數(shù)轉(zhuǎn)公歷
private?JulianDate?DD(double?jd)?{
JulianDate?julianDate?=?new?JulianDate();
int?year?month?day?hour?minute;
double?second;
int?D?=?(int)?Math.floor(jd?+?0.5)?c;
double?F?=?jd?+?0.5?-?D;?//?取得日數(shù)的整數(shù)部份A及小數(shù)部分F
if?(D?>=?2299161)?{
c?=?(int)?Math.floor((D?-?1867216.25)?/?36524.25);
D?+=?1?+?c?-?Math.floor(c?/?4);
}
D?+=?1524;
year?=?(int)?Math.floor((D?-?122.1)?/?365.25);//?年數(shù)
D?-=?Math.floor(365.25?*?year);
month?=?(int)?Math.floor(D?/?30.601);?//?月數(shù)
D?-=?Math.floor(30.601?*?month);
day?=?D;?//?日數(shù)
if?(month?>?13)?{
month?-=?13;
year?-=?4715;
}?else?{
month?-=?1;
year?-=?4716;
}
//?日的小數(shù)轉(zhuǎn)為時分秒
F?*=?24;
hour?=?(int)?Math.floor(F);
F?-=?hour;
F?*=?60;
minute?=?(int)?Math.floor(F);
F?-=?minute;
F?*=?60;
second?=?F;
julianDate.setYear(year);
julianDate.setMonth(month);
julianDate.setDay(day);
julianDate.setHour(hour);
julianDate.setMinute(minute);
julianDate.setSecond(second);
return?julianDate;
}
//日期轉(zhuǎn)為串
private?String?DD2str(JulianDate?julianDate)?{
String?Y?=?“?????“?+?julianDate.getYear()?M?=?“0“?+?julianDate.getMonth()?D?=?“0“?+?julianDate.getDay();
int?h?=?julianDate.getHour()?m?=?julianDate.getMinute()?s?=?(int)?Math.floor(julianDate.getSecond()?+?.5);
if?(s?>=?60)?{
s?-=?60;
m++;
}
if?(m?>=?60)?{
m?-=?60;
h++;
}
String?hStr?mSt
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????5724??2014-08-08?13:27??JulianDate.java
?????文件??????13408??2014-08-14?16:21??LunarCalendar.java
?????文件?????279210??2014-08-12?16:01??LunarConstant.java
?????文件???????9186??2014-08-14?15:36??LunarDate.java
-----------?---------??----------?-----??----
???????????????307528????????????????????4
評論
共有 條評論