導航:首頁 > 源碼編譯 > 農歷演算法java

農歷演算法java

發布時間:2022-12-19 17:01:38

java中陰歷的表示方法

classMyChinaDate
{
intm;
String[]month={"一","二","三","四","五","六","七","八","九","十","十一","十二"};
String[]day={"初一","初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","廿十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"};
publicvoidgetmonth(intn)
{
m=n;
if(m>=1&&m<=12)
{
switch(m)
{
case1:System.out.print("正月");break;
case12:System.out.print("臘月");break;
default:System.out.print(month[m-1]+"月");
}
}
}
publicvoidgetday(intn)
{
m=n;
if(m>=1&&m<=30)
{
System.out.println(day[m-1]);
}
}
}
publicclassMyTest
{
publicstaticvoidmain(String[]args)
{
MyChinaDatet=newMyChinaDate();
t.getmonth(1);
t.getday(6);
t.getmonth(8);
t.getday(22);
t.getmonth(12);
t.getday(30);
t.getmonth(13);
t.getday(31);
}
}

Ⅱ java中calendar獲取的時間是陰歷還是陽歷

獲取的是陽歷,補充一點,一般都是用陽歷的
陽歷也叫公歷,來源於西方。比如算星座時、就是按照陽歷(公歷)計算的。
陰歷也叫農歷,來源於我們中國。
比如我們俗稱的八月十五中秋節、清明節、七夕、春節、就是按照農歷來計算的。而元旦、和西方的情人節(2.14)和聖誕節、國慶節、建軍節、黨的生日、都是按照公歷來計算的。

他們的主要區別就在於陽歷是國際通用的,而農歷是我們中國特有的。

編程語言是國外的,怎麼可能用來獲取我們中國特有的時間呢

Ⅲ 農歷的演算法是怎麼算的

農歷一年為12或13個月,每個月天數依照月亮圍繞地球運行周期而定,為29或30天,閏年為13個月,中國農歷年平年為353或354天,閏年為384或385天,平均每年約為365.2422天(即地球環繞太陽一周的時間)。

農歷基本上以19年為一周期,對應於公歷同一時間。如公歷的2001年5月27日、1982年5月27日和1963年5月27日這個日子,都是閏四月初五。

閏月加到哪個月,以農歷歷法規則推斷,主要依照與農歷的二十四節氣相符合來確定。自冬至開始,逢單數為節氣,逢雙數為中氣,如輪到一個月只有節氣沒有中氣,即為上一個月的閏月。農歷的閏月天數與正常月份天數一樣,為29或30天。

(3)農歷演算法java擴展閱讀

農歷是我國傳統歷法,又有陰歷、華歷、夏歷、漢歷、中歷等名稱。農歷並不是純陰歷,而是一種陰陽合歷,取月相的變化周期即朔望月為月的長度,加入干支歷「二十四節氣」成分,參考太陽回歸年為年的長度,通過設置閏月以使平均歷年與回歸年相適應。農歷是以陰歷(夏歷)為基礎,融合陽歷成分而成的一種歷法。所以我國的農歷從嚴格意義上說不應該叫陰歷,而是陰陽合歷。

農歷屬於一種陰陽合歷:其年份分為平年和閏年。平年為十二個月;閏年為十三個月。月份分為大月和小月,大月三十天,小月二十九天,其平均歷月等於一個朔望月。一年中哪個月大,哪個月小,由計算決定。

農歷是兼顧太陽、月亮與地球關系的一種歷法。陰歷不考慮地球繞太陽的運行,因而使得四季的變化在陰歷上就沒有固定的時間,不能反映季節。與陽歷年固定在365天或366天不同的是,陰歷年相比陽歷年在天數上有時會相差一個月;為了協調陰歷年與陽歷年之間的天數,於是便通過「置閏法」進行調整使陰歷月相總天數與陽歷回歸年總天數相適應。

Ⅳ java怎麼取得農歷的節日

public class Lunar
{
private int year;
private int month;
private int day;
private boolean leap;
final static String chineseNumber[] =
{ "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };
final static String Big_Or_Small[] =
{ "大", "小", "大", "小", "大", "小", "大", "大", "小", "大", "小", "大" };
private String[] LunarHolDayName =
{ "小寒", "大寒", "立春", "雨水", "驚蟄", "春分", "清明", "穀雨", "立夏", "小滿", "芒種", "夏至",
"小暑", "大暑", "立秋", "處暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪",
"冬至" };

static SimpleDateFormat chineseDateFormat = new SimpleDateFormat(
" yyyy年MM月dd日 ");
final static long[] lunarInfo = new long[]
{ 0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0,
0x09ad0, 0x055d2, 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255,
0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0,
0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2,
0x04970, 0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60,
0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550,
0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557,
0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0,
0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4,
0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0,
0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540,
0x0b5a0, 0x195a6, 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a,
0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970,
0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5,
0x092e0, 0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0,
0x0abb7, 0x025d0, 0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4,
0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930,
0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0,
0x0d260, 0x0ea65, 0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7,
0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0,
0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255,
0x06d20, 0x0ada0 };

// ====== 傳回農歷 y年的總天數
final private static int yearDays(int y)
{
int i, sum = 348;
for (i = 0x8000; i > 0x8; i >>= 1)
{
if ((lunarInfo[y - 1900] & i) != 0)
sum += 1;
}
return (sum + leapDays(y));
}

// ====== 傳回農歷 y年閏月的天數
final private static int leapDays(int y)
{
if (leapMonth(y) != 0)
{
if ((lunarInfo[y - 1900] & 0x10000) != 0)
return 30;
else
return 29;
}
else
return 0;
}

// ====== 傳回農歷 y年閏哪個月 1-12 , 沒閏傳回 0
final private static int leapMonth(int y)
{
return (int) (lunarInfo[y - 1900] & 0xf);
}

// ====== 傳回農歷 y年m月的總天數
final private static int monthDays(int y, int m)
{
if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)
return 29;
else
return 30;
}

// ====== 傳回農歷 y年的生肖
final public String animalsYear()
{
final String[] Animals = new String[]
{ "鼠", "牛", "虎", "兔", "龍", "蛇", "馬", "羊", "猴", "雞", "狗", "豬" };
return Animals[(year - 4) % 12];
}

// ====== 傳入 月日的offset 傳回干支, 0=甲子
final private static String cyclicalm(int num)
{
final String[] Gan = new String[]
{ "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
final String[] Zhi = new String[]
{ "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
return (Gan[num % 10] + Zhi[num % 12]);
}

// ====== 傳入 offset 傳回干支, 0=甲子
final public String cyclical()
{
int num = year - 1900 + 36;
return (cyclicalm(num));
}

/** */
/**
* 傳出y年m月d日對應的農歷. yearCyl3:農歷年與1864的相差數 ? monCyl4:從1900年1月31日以來,閏月數
* dayCyl5:與1900年1月31日相差的天數,再加40 ?
*
* @param cal
* @return
*/
public Lunar(Calendar cal)
{
// cal.add(cal.get(Calendar.DAY_OF_MONTH),1);
@SuppressWarnings(" unused ")
int yearCyl, monCyl, dayCyl;
int leapMonth = 0;
Date baseDate = null;
try
{
baseDate = chineseDateFormat.parse(" 1900年1月31日 ");
}
catch (ParseException e)
{
e.printStackTrace(); // To change body of catch statement use
// Options | File Templates.
}

// 求出和1900年1月31日相差的天數
int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()) / 86400000L);
dayCyl = offset + 40;
monCyl = 14;

// 用offset減去每農歷年的天數
// 計算當天是農歷第幾天
// i最終結果是農歷的年份
// offset是當年的第幾天
int iYear, daysOfYear = 0;
for (iYear = 1900; iYear < 2050 && offset > 0; iYear++)
{
daysOfYear = yearDays(iYear);
offset -= daysOfYear;
monCyl += 12;
}
if (offset < 0)
{
offset += daysOfYear;
iYear--;
monCyl -= 12;
}
// 農歷年份
year = iYear;

yearCyl = iYear - 1864;
leapMonth = leapMonth(iYear); // 閏哪個月,1-12
leap = false;

// 用當年的天數offset,逐個減去每月(農歷)的天數,求出當天是本月的第幾天
int iMonth, daysOfMonth = 0;
for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++)
{
// 閏月
if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap)
{
--iMonth;
leap = true;
daysOfMonth = leapDays(year);
}
else
daysOfMonth = monthDays(year, iMonth);

offset -= daysOfMonth;
// 解除閏月
if (leap && iMonth == (leapMonth + 1))
leap = false;
if (!leap)
monCyl++;
}
// offset為0時,並且剛才計算的月份是閏月,要校正
if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1)
{
if (leap)
{
leap = false;
}
else
{
leap = true;
--iMonth;
--monCyl;
}
}
// offset小於0時,也要校正
if (offset < 0)
{
offset += daysOfMonth;
--iMonth;
--monCyl;
}
month = iMonth;
day = offset + 1;
}

public static String getChinaDayString(int day)
{
String chineseTen[] =
{ "初", "十", "廿", "卅" };
int n = day % 10 == 0 ? 9 : day % 10 - 1;
if (day > 30)
return "";
if (day == 10)
return "初十";
else
return chineseTen[day / 10] + chineseNumber[n];
}

public String toString()
{
return /* cyclical() + "年" + */(leap ? "閏" : "")
+ chineseNumber[month - 1] + "月" + getChinaDayString(day);
}

public String numeric_md()
{// 返回阿拉伯數字的陰歷日期
String temp_day;
String temp_mon;
temp_mon = month < 10 ? "0" + month : "" + month;
temp_day = day < 10 ? "0" + day : "" + day;

return temp_mon + temp_day;
}

public String get_month()
{// 返回陰歷的月份
return chineseNumber[month - 1];
}

public String get_date()
{// 返回陰歷的天
return getChinaDayString(day);
}

public String get_Big_Or_Small()
{// 返回的月份的大或小
return Big_Or_Small[month - 1];
}

}

Ⅳ 求java農歷公歷互轉演算法,發到[email protected],記住 是 公歷農歷互轉演算法,發送前請先自己檢測20個日期

星座是按陽歷(公歷)日期劃分的.

白羊座:3月21日 - 4月20日

金牛座:4月21日 - 5月21日

雙子座:5月22日 - 6月21日

巨蟹座:6月22日 - 7月22日

獅子座:7月23日 - 8月23日

處女座:8月24日 - 9月23日

天秤座:9月24日 - 10月23日

天蠍座:10月24日 - 11月22日

射手座:11月23日 - 12月21日

魔羯座:12月22日 - 1月20日

水瓶座:1月21日 - 2月19日

雙魚座:2月20日 - 3月20日

你1996年農歷11月17日出生 就是 1996年新歷的12月27日 。 你屬魔羯座。

Ⅵ 萬年歷JAVA程序上機

我這里兩個類,你跑起來看看,一個是計算農歷的,一個是拿來顯示的。

import java.util.*;
/**
* 農歷計算
*
* @author xysource
*
*/
public class LauarUtil
{

private static String[] daySTrPreArray = { "初", "十", "廿", "卅", " " };

/**
* 月份
*/
private static String[] dayStrArray = { "", "一", "二", "三", "四", "五", "六",
"七", "八", "九", "十", "十一", "十二" };

// private static String[] weekStrArray = { "", "日", "一", "二", "三", "四",
// "五", "六" };

final static long[] lunarInfo = new long[] { 0x04bd8, 0x04ae0, 0x0a570,
0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2,
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0,
0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50,
0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566,
0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0,
0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4,
0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550,
0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950,
0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260,
0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, 0x04dd5, 0x04ad0,
0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6,
0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40,
0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970, 0x064b0, 0x074a3,
0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960,
0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0,
0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9,
0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954, 0x06aa0,
0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65,
0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0,
0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, 0x056d0, 0x055b2,
0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0 };

final public static int lYearDays(int y)// ====== 傳回農歷 y年的總天數
{
int i, sum = 348;
for (i = 0x8000; i > 0x8; i >>= 1)
{
if ((lunarInfo[y - 1900] & i) != 0)
sum += 1;
}
return (sum + leapDays(y));
}

final public static int leapDays(int y)// ====== 傳回農歷 y年閏月的天數
{
if (leapMonth(y) != 0)
{
if ((lunarInfo[y - 1900] & 0x10000) != 0)
return 30;
else
return 29;
}
else
return 0;
}

final public static int leapMonth(int y)// ====== 傳回農歷 y年閏哪個月 1-12 , 沒閏傳回 0
{
return (int) (lunarInfo[y - 1900] & 0xf);
}

final public static int monthDays(int y, int m)// ====== 傳回農歷 y年m月的總天數
{
if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)
return 29;
else
return 30;
}

final public static String AnimalsYear(int y)// ====== 傳回農歷 y年的生肖
{
final String[] Animals = new String[] { "鼠", "牛", "虎", "兔", "龍", "蛇",
"馬", "羊", "猴", "雞", "狗", "豬" };
return Animals[(y - 4) % 12];
}

final public static String cyclicalm(int num)// ====== 傳入 月日的offset 傳回干支,
// 0=甲子
{
final String[] Gan = new String[] { "甲", "乙", "丙", "丁", "戊", "己", "庚",
"辛", "壬", "癸" };
final String[] Zhi = new String[] { "子", "丑", "寅", "卯", "辰", "巳", "午",
"未", "申", "酉", "戌", "亥" };
return (Gan[num % 10] + Zhi[num % 12]);
}

final public static String cyclical(int y)// ====== 傳入 offset 傳回干支, 0=甲子
{
int num = y - 1900 + 36;
return (cyclicalm(num));
}

final public long[] Lunar(int y, int m)// 傳出農歷.year0 .month1 .day2
// .yearCyl3
// .monCyl4
// .dayCyl5 .isLeap6
{
final int[] year20 = new int[] { 1, 4, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
final int[] year19 = new int[] { 0, 3, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 };
final int[] year2000 = new int[] { 0, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
long[] nongDate = new long[7];
int i = 0, temp = 0, leap = 0;
Date baseDate = new Date(1900, 1, 31);
Date objDate = new Date(y, m, 1);
long offset = (objDate.getTime() - baseDate.getTime()) / 86400000L;
if (y < 2000)
offset += year19[m - 1];
if (y > 2000)
offset += year20[m - 1];
if (y == 2000)
offset += year2000[m - 1];
nongDate[5] = offset + 40;
nongDate[4] = 14;

for (i = 1900; i < 2050 && offset > 0; i++)
{
temp = lYearDays(i);
offset -= temp;
nongDate[4] += 12;
}
if (offset < 0)
{
offset += temp;
i--;
nongDate[4] -= 12;
}
nongDate[0] = i;
nongDate[3] = i - 1864;
leap = leapMonth(i); // 閏哪個月
nongDate[6] = 0;

for (i = 1; i < 13 && offset > 0; i++)
{
// 閏月
if (leap > 0 && i == (leap + 1) && nongDate[6] == 0)
{
--i;
nongDate[6] = 1;
temp = leapDays((int) nongDate[0]);
}
else
{
temp = monthDays((int) nongDate[0], i);
}

// 解除閏月
if (nongDate[6] == 1 && i == (leap + 1))
nongDate[6] = 0;
offset -= temp;
if (nongDate[6] == 0)
nongDate[4]++;
}

if (offset == 0 && leap > 0 && i == leap + 1)
{
if (nongDate[6] == 1)
{
nongDate[6] = 0;
}
else
{
nongDate[6] = 1;
--i;
--nongDate[4];
}
}
if (offset < 0)
{
offset += temp;
--i;
--nongDate[4];
}
nongDate[1] = i;
nongDate[2] = offset + 1;
return nongDate;
}

final public static long[] calElement(int y, int m, int d)
// 傳出y年m月d日對應的農歷.year0 .month1 .day2 .yearCyl3 .monCyl4 .dayCyl5 .isLeap6
{
long[] nongDate = new long[7];
int i = 0, temp = 0, leap = 0;
Date baseDate = new Date(0, 0, 31);
Date objDate = new Date(y - 1900, m - 1, d);
long offset = (objDate.getTime() - baseDate.getTime()) / 86400000L;
nongDate[5] = offset + 40;
nongDate[4] = 14;

for (i = 1900; i < 2050 && offset > 0; i++)
{
temp = lYearDays(i);
offset -= temp;
nongDate[4] += 12;
}
if (offset < 0)
{
offset += temp;
i--;
nongDate[4] -= 12;
}
nongDate[0] = i;
nongDate[3] = i - 1864;
leap = leapMonth(i); // 閏哪個月
nongDate[6] = 0;

for (i = 1; i < 13 && offset > 0; i++)
{
// 閏月
if (leap > 0 && i == (leap + 1) && nongDate[6] == 0)
{
--i;
nongDate[6] = 1;
temp = leapDays((int) nongDate[0]);
}
else
{
temp = monthDays((int) nongDate[0], i);
}

// 解除閏月
if (nongDate[6] == 1 && i == (leap + 1))
nongDate[6] = 0;
offset -= temp;
if (nongDate[6] == 0)
nongDate[4]++;
}

if (offset == 0 && leap > 0 && i == leap + 1)
{
if (nongDate[6] == 1)
{
nongDate[6] = 0;
}
else
{
nongDate[6] = 1;
--i;
--nongDate[4];
}
}
if (offset < 0)
{
offset += temp;
--i;
--nongDate[4];
}
nongDate[1] = i;
nongDate[2] = offset + 1;
return nongDate;
}

public static String getchina(int day)
{
if (day == 10)
return "初十";
if (day == 20)
return "二十";
if (day == 30)
return "三十";
String a = daySTrPreArray[(int) ((day) / 10)];
//System.out.println(a);
a += dayStrArray[(int) (day % 10)];
return a;
}

public static String getLauar(Calendar cld)
{
int year = cld.get(Calendar.YEAR);
int month = cld.get(Calendar.MONTH) + 1;
int day = cld.get(Calendar.DAY_OF_MONTH);

long[] lauarStrArray = calElement(year, month, day);
String monthStr = dayStrArray[(int) (lauarStrArray[1])];
return monthStr + "月" + getchina((int) (lauarStrArray[2]));//AnimalsYear(1989)+"年農歷" +
}

public static void main(String[] args)
{
Calendar cld = Calendar.getInstance();
// for (int i = 0; i < 145; i++) {
System.out.println(getLauar(cld));
// cld.add(Calendar.DAY_OF_MONTH, 1);
// }
}

}

Ⅶ 如何用java編寫帶時鍾的萬年歷代碼,萬年歷要有陰歷演算法

如圖:

來源:http://www.javaeye.com/topic/735220

如調試不成功,我把源碼發你信箱里

Ⅷ java計算農歷日期

import java.util.Scanner;public class PrintCalendar { /**
* @param args
*/
public static void main(String[] args) {
System.out.println("******************歡 迎 使 用 萬 年 歷******************");
Scanner input = new Scanner(System.in);
System.out.print("\n請選擇年份: ");
int year = input.nextInt();
System.out.print("\n請選擇月份: ");
int month = input.nextInt();
System.out.println(); int days = 0; // 存儲當月的天數
boolean isRn;
/* 判斷是否是閏年 */
if (year % 4 == 0 && !(year % 100 == 0) || year % 400 == 0) { // 判斷是否為閏年
isRn = true; // 閏年
} else {
isRn = false;// 平年
} /* 計算輸入的年份之前的天數 */
int totalDays = 0;
for (int i = 1900; i < year; i++) {
/* 判斷閏年或平年,並進行天數累加 */
if (i % 4 == 0 && !(i % 100 == 0) || i % 400 == 0) { // 判斷是否為閏年
totalDays = totalDays + 366; // 閏年366天
} else {
totalDays = totalDays + 365; // 平年365天
}
} /* 計算輸入月份之前的天數 */
int beforeDays = 0;
for (int i = 1; i <= month; i++) {
switch (i) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
case 2:
if (isRn) {
days = 29;
} else {
days = 28;
}
break;
default:
days = 30;
break;
}
if (i < month) {
beforeDays = beforeDays + days;
}
}
totalDays = totalDays + beforeDays; // 距離1900年1月1日的天數 /* 計算星期幾 */
int firstDayOfMonth; // 存儲當月第一天是星期幾:星期日為0,星期一~星期六為1~6
int temp = 1 + totalDays % 7; // 從1900年1月1日推算
if (temp == 7) { // 求當月第一天
firstDayOfMonth = 0; // 周日
} else {
firstDayOfMonth = temp;
} /* 輸出日歷 */
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
for (int nullNo = 0; nullNo < firstDayOfMonth; nullNo++) {
System.out.print("\t"); // 輸出空格
}
for (int i = 1; i <= days; i++) {
System.out.print(i + "\t");
if ((totalDays + i - 1) % 7 == 5) { // 如果當天為周六,輸出換行
System.out.println();
}
}
}
}

Ⅸ Java怎樣編程實現農歷和陽歷轉換

public class TestNongLi {
public static void main(String[] args) {
// 調用農歷日期轉換陽歷日期方法
System.out.println(ChineseCalendar.sCalendarLundarToSolar(2008, 1, 1));
}
}
// 自定義日歷類
class ChineseCalendar {
// Array lIntLunarDay is stored in the monthly day information in every year from 1901 to 2100 of the lunar calendar,
// The lunar calendar can only be 29 or 30 days every month, express with 12(or 13) pieces of binary bit in one year,
// it is 30 days for 1 form in the corresponding location , otherwise it is 29 days
private static final int[] iLunarmont

Ⅹ 用java如何獲取當前時間的農歷

int weekDay = java.util.Calendar.getInstance().get(java.util.Calendar.DAY_OF_WEEK);
這個得出的是一個星期的第幾天。

閱讀全文

與農歷演算法java相關的資料

熱點內容
567除以98的簡便演算法 瀏覽:338
pdf手機如何解壓 瀏覽:15
python描述器 瀏覽:60
戰地聯盟3解壓密碼 瀏覽:805
s型命令 瀏覽:25
php年薪5年 瀏覽:71
如何上網上設個人加密賬戶 瀏覽:44
linux打開ssh服務 瀏覽:78
微信位置可以加密嗎 瀏覽:470
演算法蠻力法 瀏覽:438
隨機排練命令 瀏覽:147
python多進程並發 瀏覽:41
安卓軟體安裝如何躲避安全檢測 瀏覽:647
奇幻潮翡翠台源碼百度雲盤 瀏覽:187
什麼軟體可以免費pdf轉word 瀏覽:15
php正則表達式大全 瀏覽:394
androidntp時間 瀏覽:299
輪機長命令簿英文 瀏覽:148
oppo鈴聲設置被加密怎麼處理 瀏覽:548
粵苗app圖形驗證碼怎麼填 瀏覽:899