java获取农历 国历转农历 我在网上找了一个方法

万年历 公历农历查询 (公元年公历农历日历表)
二十四节气
&选 择 年 月
&快 速 查 询 通 道
公历查农历
农历查公历
公历 2015 年 6 月 农历 乙未年 生肖:羊
芒种:日&07:51时&&&&夏至:日&00:29时
& & & & & & &
& & & & & &
注意:由于农历24节气交节时刻采用近似算法,可能存在少量误差(30分钟内);时干支为当前时辰。java,阳历转阴历(农历) - 细节决定成败 - ITeye技术网站
博客分类:
转自:http://www.blogjava.net/soddabao/archive//91729.html
前几天在blog中,对网友的java万年历作修改,看到有的网友说能不能加上农历,后来在网上看到有人写过几个阳历转阴历的算法,我比较了一个发现,这个算法还算不错,只要有的计算机编程基础的人看明白应该是没有问题的,其实这个就和我们以前在c中,判断一天是周几的算法差不多,都是和某一个特定的时间作比较,算出差多少天,再根据月大月小瑞月这些规则,算出是农历的那年那月那日.
import java.text.ParseE
import java.text.SimpleDateF
import java.util.C
import java.util.D
public class Lunar {
final static String chineseNumber[] = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};
static SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
final static long[] lunarInfo = new long[]
{0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x1a0, 0x09ad0, 0x055d2,
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977,
0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x0f2, 0x04970,
0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950,
0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557,
0x06ca0, 0x0b550, 0x1da0, 0x0a5d0, 0x1d0, 0x0a9a8, 0x0e950, 0x06aa0,
0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 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, 0x0b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0,
0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x0a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5,
0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x1b0, 0x0a930,
0x0aa0, 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;
return 29;
//====== 传回农历 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;
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:从日以来,闰月数
* dayCyl5:与日相差的天数,再加40
* @param cal
public Lunar(Calendar cal) {
@SuppressWarnings("unused") int yearCyl, monCyl, dayC
int leapMonth = 0;
Date baseDate =
baseDate = chineseDateFormat.parse("日");
} catch (ParseException e) {
e.printStackTrace();
//To change body of catch statement use Options | File Templates.
//求出和日相差的天数
int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()) / L);
dayCyl = offset + 40;
monCyl = 14;
//用offset减去每农历年的天数
// 计算当天是农历第几天
//i最终结果是农历的年份
//offset是当年的第几天
int iYear, daysOfYear = 0;
for (iYear = 1900; iYear & 2050 && offset & 0; iYear++) {
daysOfYear = yearDays(iYear);
offset -= daysOfY
monCyl += 12;
if (offset & 0) {
offset += daysOfY
monCyl -= 12;
//农历年份
yearCyl = iYear - 1864;
leapMonth = leapMonth(iYear); //闰哪个月,1-12
//用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
int iMonth, daysOfMonth = 0;
for (iMonth = 1; iMonth & 13 && offset & 0; iMonth++) {
if (leapMonth & 0 && iMonth == (leapMonth + 1) && !leap) {
daysOfMonth = leapDays(year);
daysOfMonth = monthDays(year, iMonth);
offset -= daysOfM
//解除闰月
if (leap && iMonth == (leapMonth + 1)) leap =
if (!leap) monCyl++;
//offset为0时,并且刚才计算的月份是闰月,要校正
if (offset == 0 && leapMonth & 0 && iMonth == leapMonth + 1) {
if (leap) {
//offset小于0时,也要校正
if (offset & 0) {
offset += daysOfM
month = iM
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 "初十";
return chineseTen[day / 10] + chineseNumber[n];
public String toString() {
return year + "年" + (leap ? "闰" : "") + chineseNumber[month - 1] + "月" + getChinaDayString(day);
public static void main(String[] args) throws ParseException {
Calendar today = Calendar.getInstance();
today.setTime(chineseDateFormat.parse("日"));
Lunar lunar = new Lunar(today);
System.out.println("北京时间:" + chineseDateFormat.format(today.getTime()) + " 农历" + lunar);
浏览: 54476 次
来自: 深圳
博主你好, 假如我知道 农历 是 6 16(数据库中存的是这个 ...
lz口中的主力浏览器仅包括IE6吧。测试过几个浏览器啊。。。。 ...
看上去比较简陋,是纯html的表单设计器还是基于某些js框架的 ...
能给分享一下源码么?我想参考下么,万分感谢啊
szwangd ...
源码 参考下 么当前访客身份:游客 [
当前位置:
发布于 日 23时,
&无详细内容&
代码片段(1)
1.&[代码]LunarCalendar.java&&&&
* LunarCalendar.java
* 作者: Winter Lau
package my.
import java.text.SimpleDateF
import java.util.C
import java.util.D
import java.util.GregorianC
import java.util.L
* 农历的一些方法
* @author Winter Lau
public class LunarCalendar {
final private static long[] lunarInfo = new long[] { 0x04bd8, 0x04ae0, 0x0a570,
0x054d5, 0x0d260, 0x0d950, 0x1a0, 0x09ad0, 0x055d2,
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0,
0x0ada2, 0x095b0, 0x170, 0x0a4b0, 0x0b4b5, 0x06a50,
0x06d40, 0x1ab54, 0x02b60, 0x0f2, 0x066,
0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0,
0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4,
0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550,
0x1da0, 0x0a5d0, 0x1d0, 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, 0x0af5, 0x0b0, 0x074a3,
0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960,
0x0d954, 0x0d4a0, 0x0da50, 0x0a0, 0x0abb7, 0x025d0,
0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9,
0x04ba0, 0x0a5b0, 0x1b0, 0x0a930, 0x0aa0,
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 };
//private final static String[] week = new String[]{"日","一","二","三","四","五","六"};
final private static int[] year20 = new int[] { 1, 4, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
final private static int[] year19 = new int[] { 0, 3, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 };
final private static int[] year2000 = new int[] { 0, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
//private final static String[] nStr1 = new String[]{"","正","二","三","四","五","六","七","八","九","十","十一","十二"};
private final static String[] Gan=new String[]{"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
private final static String[] Zhi=new String[]{"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"};
private final static String[] Animals=new String[]{"鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};
* 传回农历 y年的总天数
* @param y
final private static int lYearDays(int y){
int i, sum = 348;
for (i = 0x8000; i & 0x8; i &&= 1) {
if ((lunarInfo[y - 1900] & i) != 0)
return (sum + leapDays(y));
* 传回农历 y年闰月的天数
* @param y
final private static int leapDays(int y){
if (leapMonth(y) != 0) {
if ((lunarInfo[y - 1900] & 0x10000) != 0)
return 30;
return 29;
* 传回农历 y年闰哪个月 1-12 , 没闰传回 0
* @param y
final private static int leapMonth(int y){
return (int) (lunarInfo[y - 1900] & 0xf);
* 传回农历 y年m月的总天数
* @param y
* @param m
final private static int monthDays(int y, int m){
if ((lunarInfo[y - 1900] & (0x10000 && m)) == 0)
return 29;
return 30;
* 传回农历 y年的生肖
* @param y
final public static String AnimalsYear(int y){
return Animals[(y - 4) % 12];
* 传入 月日的offset 传回干支,0=甲子
* @param num
final private static String cyclicalm(int num)
return (Gan[num % 10] + Zhi[num % 12]);
* 传入 offset 传回干支, 0=甲子
* @param y
final public static String cyclical(int y){
int num = y - 1900 + 36;
return (cyclicalm(num));
* 传出农历.year0 .month1 .day2 .yearCyl3 .monCyl4 .dayCyl5 .isLeap6
* @param y
* @param m
protected final long[] Lunar(int y, int m) {
long[] nongDate = new long[7];
int i = 0, temp = 0, leap = 0;
//Date baseDate = new Date();
Date baseDate = new GregorianCalendar(,31).getTime();
//Date objDate = new Date(y, m, 1);
Date objDate = new GregorianCalendar(y+1900,m,1).getTime();
long offset = (objDate.getTime() - baseDate.getTime()) / L;
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);
nongDate[4] += 12;
if (offset & 0) {
nongDate[4] -= 12;
nongDate[0] =
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) {
nongDate[6] = 1;
temp = leapDays((int) nongDate[0]);
temp = monthDays((int) nongDate[0], i);
// 解除闰月
if (nongDate[6] == 1 && i == (leap + 1))
nongDate[6] = 0;
if (nongDate[6] == 0)
nongDate[4]++;
if (offset == 0 && leap & 0 && i == leap + 1) {
if (nongDate[6] == 1) {
nongDate[6] = 0;
nongDate[6] = 1;
--nongDate[4];
if (offset & 0) {
--nongDate[4];
nongDate[1] =
nongDate[2] = offset + 1;
return nongD
* 传出y年m月d日对应的农历.year0 .month1 .day2 .yearCyl3 .monCyl4 .dayCyl5 .isLeap6
* @param y
* @param m
* @param d
final public static long[] calElement(int y, int m, int d)
long[] nongDate = new long[7];
int i = 0, temp = 0, leap = 0;
//Date baseDate = new Date(0, 0, 31);
Date baseDate = new GregorianCalendar(0+).getTime();
//Date objDate = new Date(y - 1900, m - 1, d);
Date objDate = new GregorianCalendar(y,m-1,d).getTime();
long offset = (objDate.getTime() - baseDate.getTime()) / L;
nongDate[5] = offset + 40;
nongDate[4] = 14;
for (i = 1900; i & 2050 && offset & 0; i++) {
temp = lYearDays(i);
nongDate[4] += 12;
if (offset & 0) {
nongDate[4] -= 12;
nongDate[0] =
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) {
nongDate[6] = 1;
temp = leapDays((int) nongDate[0]);
temp = monthDays((int) nongDate[0], i);
// 解除闰月
if (nongDate[6] == 1 && i == (leap + 1))
nongDate[6] = 0;
if (nongDate[6] == 0)
nongDate[4]++;
if (offset == 0 && leap & 0 && i == leap + 1) {
if (nongDate[6] == 1) {
nongDate[6] = 0;
nongDate[6] = 1;
--nongDate[4];
if (offset & 0) {
--nongDate[4];
nongDate[1] =
nongDate[2] = offset + 1;
return nongD
public final static String getChinaDate(int day) {
String a = "";
if (day == 10)
return "初十";
if(day==20)
return "二十";
if(day==30)
return "三十";
int two = (int) ((day) / 10);
if (two == 0)
if (two == 1)
if (two == 2)
if (two == 3)
int one = (int) (day % 10);
switch (one) {
a += "一";
a += "二";
a += "三";
a += "四";
a += "五";
a += "六";
a += "七";
a += "八";
a += "九";
public static long[] today(){
Calendar today = Calendar.getInstance(Locale.SIMPLIFIED_CHINESE);
int year = today.get(Calendar.YEAR);
int month = today.get(Calendar.MONTH)+1;
int date = today.get(Calendar.DATE);
long[] l = calElement(year, month, date);
public static long[] get(Calendar today){
int year = today.get(Calendar.YEAR);
int month = today.get(Calendar.MONTH)+1;
int date = today.get(Calendar.DATE);
long[] l = calElement(year, month, date);
* 返回代表今日时间的字符串
* @param locale
public static String today(Locale locale){
if(locale == null)
locale = Locale.SIMPLIFIED_CHINESE;
Calendar today = Calendar.getInstance(locale);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 EEE", locale);
return sdf.format(today.getTime());
* 农历日历工具使用演示
* @param args
public static void main(String[] args) {
//System.out.println("今天是:"+week());
开源中国-程序员在线工具:
相关的代码(16)
5回/5273阅
6回/4933阅
18回/4546阅
0回/3449阅
1回/3008阅
6回/2924阅
8回/2165阅
16回/1905阅
4回/1965阅
0回/1907阅
2楼:黄绍添 发表于
我看了很多农历算法,不知道为什么,在日那天得出的农历都是七月廿一,但真正的农历应该是七月廿二啊,到底是算少了哪一天?
3楼:itblackhole 发表于
怎么运行不了?
4楼:半醒 发表于
引用来自“黄绍添”的评论我看了很多农历算法,不知道为什么,在日那天得出的农历都是七月廿一,但真正的农历应该是七月廿二啊,到底是算少了哪一天?
/view/839e356aaf1ffc4ffe47aca2.html试了下这个的算法,89年的农历月大月小好像搞错了,换成0x9570就正确了,不知道还有没有其他月份算错的
5楼:张崇彪 发表于
很多农历算法号1个月之内基本都有误啊,什么原因
6楼:wanpg 发表于
号和4月11号的农历是同一天,都是阴历2月二十八怎么办
7楼:懒萝卜 发表于
,来看下。 的日期确实有错误。
8楼:guxingxin 发表于
求offset的时候,四舍五入就没错
开源从代码分享开始
红薯的其他代码54java 农历转阳历类
上亿文档资料,等你来发现
54java 农历转阳历类
//测试类;publicclassTest{;publicstaticvoidmain(Str;//调用农历日期转换阳历日期方法;System.out.println(Calen;//自定义日历类;classCalendar{;//ArraylIntLunarDayissto;//fromofthelun;//Thelunarcalend
//测试类public class Test {public static void main(String[] args) {// 调用农历日期转换阳历日期方法System.out.println(Calendar.sCalendarLundarToSolar());}}// 自定义日历类class Calendar {// 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/*** 高12位表示12个月的天数,1表示30天,0表示29天*/public static final int[] iLunarMonthDaysTable = {0x4ae0,0xa570,0x0,0xd950,0x6aa8,0x56a0,0x9ad0,0x4ae8,0x4ae0,//19100xa4d8,0xa4d0,0xd250,0xd548,0xb550,0x56a0,0x96d0,0x95b0,0x49b8,0x49b0,//19200xa4b0,0xb258,0x6a50,0x6d40,0xada8,0x2b60,0x8,0xb0,//19300xd4a0,0xea50,0x6d48,0x5ad0,0x2b60,0xe0,0xc968,0xc950,0xd4a0,//19400xda50,0xb550,0x56a0,0xaad8,0x25d0,0x92d0,0xc958,0xa950,0xb4a8,0x6ca0,//19500xb550,0x55a8,0x4da0,0xa5b0,0x52b8,0x52b0,0xa950,0xe950,0x6aa0,0xad50,//19600xab50,0x4b60,0xa570,0xa570,0x0,0xd950,0x5aa8,0x56a0,0x96d0,//19700x4ae8,0x4ad0,0xa4d0,0xd268,0xd250,0xd528,0xb540,0xb6a0,0x96d0,0x95b0,//19800x49b0,0xa4b8,0xa4b0,0xb258,0x6a50,0x6d40,0xada0,0xab60,0x8,//19900xb0,0x6a50,0xea50,0x6b28,0x5ac0,0xab60,0xe0,0xc960,//20000xd4a8,0xd4a0,0xda50,0x5aa8,0x56a0,0xaad8,0x25d0,0x92d0,0xc958,0xa950,//20100xb4a0,0xb550,0xb550,0x55a8,0x4ba0,0xa5b0,0x52b8,0x52b0,0xa930,0x74a8,//20200x6aa0,0xad50,0x4da8,0x4b60,0xe0,0xd260,0xe930,0xd530,0x5aa0,//20300x6b50,0x96d0,0x4ae8,0x4ad0,0xa4d0,0xd258,0xd250,0xd520,0xdaa0,0xb5a0,//20400x56d0,0x4ad8,0x49b0,0xa4b8,0xa4b0,0xaa50,0xb528,0x6d20,0xada0,0x55b0//2050};// Array iLunarLeapMonthTable preserves the lunar calendar leap month from// 1901 to 2050,// if it is 0 express not to have , every byte was stored for two years/*** 利用8位字节来存储农历某年闰哪个月* 高四位存奇数年,低四位存偶数年* 如年都存在iLunarLeapMonthTable[0]中* 1903年闰5月,1904年无闰月*/public static final char[] iLunarLeapMonthTable = { 0x00, 0x50, 0x04,0x00, 0x20, // 19100x60, 0x05, 0x00, 0x20, 0x70, // 19200x05, 0x00, 0x40, 0x02, 0x06, // 19300x00, 0x50, 0x03, 0x07, 0x00, // 19400x60, 0x04, 0x00, 0x20, 0x70, // 19500x05, 0x00, 0x30, 0x80, 0x06, // 19600x00, 0x40, 0x03, 0x07, 0x00, // 19700x50, 0x04, 0x08, 0x00, 0x60, // 19800x04, 0x0a, 0x00, 0x60, 0x05, // 19900x00, 0x30, 0x80, 0x05, 0x00, // 20000x40, 0x02, 0x07, 0x00, 0x50, // 20100x04, 0x09, 0x00, 0x60, 0x04, // 20200x00, 0x20, 0x60, 0x05, 0x00, // 20300x30, 0xb0, 0x06, 0x00, 0x50, // 20400x02, 0x07, 0x00, 0x50, 0x03 // 2050};// Array iSolarLunarTable stored the offset days// in New Year of solar calendar and lunar calendar from 1901 to 2050;/*** 大年初一离同一年元旦的天数*/public static final char[] iSolarLunarOffsetTable = { 49, 38, 28, 46, 34, 24, 43, 32, 21, 40, // 191029, 48, 36, 25, 44, 34, 22, 41, 31, 50, // 192038, 27, 46, 35, 23, 43, 32, 22, 40, 29, // 193047, 36, 25, 44, 34, 23, 41, 30, 49, 38, // 194026, 45, 35, 24, 43, 32, 21, 40, 28, 47, // 195036, 26, 44, 33, 23, 42, 30, 48, 38, 27, // 196045, 35, 24, 43, 32, 20, 39, 29, 47, 36, // 197026, 45, 33, 22, 41, 30, 48, 37, 27, 46, // 198035, 24, 43, 32, 50, 39, 28, 47, 36, 26, // 199045, 34, 22, 40, 30, 49, 37, 27, 46, 35, // 200023, 42, 31, 21, 39, 28, 48, 37, 25, 44, // 201033, 23, 41, 31, 50, 39, 28, 47, 35, 24, // 202042, 30, 21, 40, 28, 47, 36, 25, 43, 33, // 203022, 41, 30, 49, 37, 26, 44, 33, 23, 42, // 204031, 21, 40, 29, 47, 36, 25, 44, 32, 22, // 2050};static boolean bIsSolarLeapYear(int iYear) {return ((iYear % 4 == 0) && (iYear % 100 != 0) || iYear % 400 == 0);}/*** 返回阳历iYear年iMonth月的天数* @param iYear* @param iMonth* @return*/static int iGetSYearMonthDays(int iYear, int iMonth) {if ((iMonth == 1) || (iMonth == 3) || (iMonth == 5) || (iMonth == 7)|| (iMonth == 8) || (iMonth == 10) || (iMonth == 12))return 31;else if ((iMonth == 4) || (iMonth == 6) || (iMonth == 9)|| (iMonth == 11))return 30;else if (iMonth == 2) {if (bIsSolarLeapYear(iYear))return 29;elsereturn 28;} elsereturn 0;}// The offset days from New Year and the day when point out in solar// calendar/*static int iGetSNewYearOffsetDays(int iYear, int iMonth, int iDay) {int iOffsetDays = 0;for (int i = 1; i & iM i++) {iOffsetDays += iGetSYearMonthDays(iYear, i);}iOffsetDays += iDay - 1;return iOffsetD}*//*** 计算农历iYear年是闰几月* @param iYear* @return*/static int iGetLLeapMonth(int iYear) {char iMonth = iLunarLeapMonthTable[(iYear - 1901) / 2];if (iYear % 2 == 0)return (iMonth & 0x0f);elsereturn (iMonth & 0xf0) && 4;}/*** 得到农历iYear年iMonth月的天数* @param iYear* @param iMonth* @return*/static int iGetLMonthDays(int iYear, int iMonth) {int iLeapMonth = iGetLLeapMonth(iYear);if ((iMonth & 12) && (iMonth - 12 != iLeapMonth) || (iMonth & 0)) {System.out.println(&Wrong month, ^_^ , i think you are want a -1, go to death!&);return -1;}if (iMonth - 12 == iLeapMonth) {if ((iLunarMonthDaysTable[iYear - 1901] & (0x8000 && iLeapMonth)) == 0)return 29;elsereturn 30;}if ((iLeapMonth & 0) && (iMonth & iLeapMonth))iMonth++;if ((iLunarMonthDaysTable[iYear - 1901] & (0x8000 && (iMonth - 1))) == 0)return 29;elsereturn 30;}/*// Days in this year of lunar calendarstatic int iGetLYearDays(int iYear) {int iYearDays = 0;int iLeapMonth = iGetLLeapMonth(iYear);for (int i = 1; i & 13; i++)iYearDays += iGetLMonthDays(iYear, i);if (iLeapMonth & 0)iYearDays += iGetLMonthDays(iYear, iLeapMonth + 12);return iYearD}*//*** 计算该农历日期离大年初一的天数* @param iYear* @param iMonth* @param iDay* @return*/static int iGetLNewYearOffsetDays(int iYear, int iMonth, int iDay) {int iOffsetDays = 0;int iLeapMonth = iGetLLeapMonth(iYear);//System.out.println(&iLeapMonth: & + iYear + & & + iLeapMonth);if ((iLeapMonth & 0) && (iLeapMonth == iMonth - 12)) {iMonth = iLeapMiOffsetDays += iGetLMonthDays(iYear, iMonth);}//for (int i = 1; i & iM i++) {iOffsetDays += iGetLMonthDays(iYear, i);if (i == iLeapMonth)iOffsetDays += iGetLMonthDays(iYear, iLeapMonth + 12);}iOffsetDays += iDay - 1;return iOffsetD}// The solar calendar is turned into the lunar calendar/*static String sCalendarSolarToLundar(int iYear, int iMonth, int iDay) {int iLDay, iLMonth, iLYint iOffsetDays = iGetSNewYearOffsetDays(iYear, iMonth, iDay);int iLeapMonth = iGetLLeapMonth(iYear);if (iOffsetDays & iSolarLunarOffsetTable[iYear - 1901]) {iLYear = iYear - 1;iOffsetDays = iSolarLunarOffsetTable[iYear - 1901] - iOffsetDiLDay = iOffsetDfor (iLMonth = 12; iOffsetDays & iGetLMonthDays(iLYear, iLMonth); iLMonth--) {iLDay = iOffsetDiOffsetDays -= iGetLMonthDays(iLYear, iLMonth);}if (0 == iLDay)iLDay = 1;elseiLDay = iGetLMonthDays(iLYear, iLMonth) - iOffsetDays + 1;} else {iLYear = iYiOffsetDays -= iSolarLunarOffsetTable[iYear - 1901];iLDay = iOffsetDays + 1;for (iLMonth = 1; iOffsetDays &= 0; iLMonth++) {iLDay = iOffsetDays + 1;iOffsetDays -= iGetLMonthDays(iLYear, iLMonth);if ((iLeapMonth == iLMonth) && (iOffsetDays & 0)) {iLDay = iOffsetDiOffsetDays -= iGetLMonthDays(iLYear, iLMonth + 12);if (iOffsetDays &= 0) {iLMonth += 12 + 1;}}}iLMonth--;}return && + iLYear + (iLMonth & 9 ? && + iLMonth : &0& + iLMonth)+ (iLDay & 9 ? && + iLDay : &0& + iLDay);}*//*** 将农历日期转换为阳历日期* @param iYear* @param iMonth* @param iDay* @return*/static String sCalendarLundarToSolar(int iYear, int iMonth, int iDay) {int iSYear, iSMonth, iSD//农历iYear年iMonth月iDay日里iYear年元旦的天数int iOffsetDays = iGetLNewYearOffsetDays(iYear, iMonth, iDay)+ iSolarLunarOffsetTable[iYear - 1901];//System.out.println(&iOffsetDays & + iOffsetDays);//System.out.println(&days: & + iGetLMonthDays(2012, 16));int iYearDays = bIsSolarLeapYear(iYear) ? 366: 365;if (iOffsetDays &= iYearDays) {iSYear = iYear + 1;iOffsetDays -= iYearD} else {iSYear = iY}iSDay = iOffsetDays + 1;for (iSMonth = 1; iOffsetDays &= 0; iSMonth++) {iSDay = iOffsetDays + 1;iOffsetDays -= iGetSYearMonthDays(iSYear, iSMonth);}iSMonth--;return && + iSYear + (iSMonth & 9 ? iSMonth + && : &0& + iSMonth)+ (iSDay & 9 ? iSDay + && : &0& + iSDay);}}/*// 自定义星期类class Week {int iWprivate String sWeek[] = { &Sunday&, &Monday&, &Tuesday&, &Wednesday&,&Thursday&, &Friday&, &Saturday& };public Week() {iWeek = 0;}public Week(int w) {if ((w & 6) || (w & 0)) {System.out.println(&Week out of range, I think you want Sunday&);this.iWeek = 0;} elsethis.iWeek =}public String toString() {return sWeek[iWeek];}}*//*// 自定义日期类class MyDate {public int iYpublic int iMpublic int iDprivate static int checkYear(int iYear) {if ((iYear & 1901) && (iYear & 2050))return iYelse {System.out.println(&The Year out of range, I think you want 1981&);return 1981;}}public MyDate(int iYear, int iMonth, int iDay) {this.iYear = checkYear(iYear);this.iMonth = iMthis.iDay = iD}public MyDate(int iYear, int iMonth) {this.iYear = checkYear(iYear);this.iMonth = iMthis.iDay = 1;}public MyDate(int iYear) {this.iYear = checkYear(iYear);this.iMonth = 1;this.iDay = 1;}public MyDate() {this.iYear = 1981;this.iMonth = 1;this.iDay = 1;}public String toString() {return && + this.iYear+ (this.iMonth & 9 ? && + this.iMonth : &0& + this.iMonth)+ (this.iDay & 9 ? && + this.iDay : &0& + this.iDay);}public boolean equals(MyDate md) {return ((md.iDay == this.iDay) && (md.iMonth == this.iMonth) && (md.iYear == this.iYear));}}*/// 阳历日期类,继承自定义日期/*class SolarDate extends MyDate {private static int checkMonth(int iMonth) {if (iMonth & 12) {System.out.println(&Month out of range, I think you want 12 :)&);return 12;} else if (iMonth & 1) {System.out.println(&Month out of range, I think you want 1 :)&);return 1;} elsereturn iM}private static int checkDay(int iYear, int iMonth, int iDay) {int iMonthDays = Calendar.iGetSYearMonthDays(iYear, iMonth);if (iDay & iMonthDays) {System.out.println(&Day out of range, I think you want &+ iMonthDays + & :)&);return iMonthD} else if (iDay & 1) {System.out.println(&Day out of range, I think you want 1 :)&);return 1;} elsereturn iD}public SolarDate(int iYear, int iMonth, int iDay) {super(iYear);this.iMonth = checkMonth(iMonth);this.iDay = checkDay(this.iYear, this.iMonth, iDay);}public SolarDate(int iYear, int iMonth) {super(iYear);this.iMonth = checkMonth(iMonth);}public SolarDate(int iYear) {super(iYear);}public SolarDate() {super();}public String toString() {return && + this.iYear+ (this.iMonth & 9 ? &-& + this.iMonth : &-0& + this.iMonth)+ (this.iDay & 9 ? &-& + this.iDay : &-0& + this.iDay);}public Week toWeek() {int iOffsetDays = 0;for (int i = 1901; i & iY i++) {if (Calendar.bIsSolarLeapYear(i))iOffsetDays += 366;elseiOffsetDays += 365;}iOffsetDays += Calendar.iGetSNewYearOffsetDays(iYear, iMonth, iDay);return new Week((iOffsetDays + 2) % 7);}public LunarDate toLunarDate() {int iYear, iMonth, iDay, iDLunarDiDate = Integer.parseInt(Calendar.sCalendarSolarToLundar(this.iYear,this.iMonth, this.iDay));iYear = iDate / 10000;iMonth = iDate % 10000 / 100;iDay = iDate % 100;ld = new LunarDate(iYear, iMonth, iDay);}}*/// 阴历日期类,继承自定义日期类/*class LunarDate extends MyDate {private String sChineseNum[] = { &零&, &一&, &二&, &三&, &四&, &五&, &六&, &七&,&八&, &九&, &十& };private static int checkMonth(int iYear, int iMonth) {if ((iMonth & 12) && (iMonth == Calendar.iGetLLeapMonth(iYear) + 12)) {return iM} else if (iMonth & 12) {System.out.println(&Month out of range, I think you want 12 :)&);return 12;} else if (iMonth & 1) {System.out.println(&Month out of range, I think you want 1 :)&);return 1;} elsereturn iM}private static int checkDay(int iYear, int iMonth, int iDay) {int iMonthDays = Calendar.iGetLMonthDays(iYear, iMonth);if (iDay & iMonthDays) {System.out.println(&Day out of range, I think you want &+ iMonthDays + & :)&);return iMonthD} else if (iDay & 1) {System.out.println(&Day out of range, I think you want 1 :)&);return 1;} elsereturn iD}public LunarDate(int iYear, int iMonth, int iDay) {super(iYear);this.iMonth = checkMonth(this.iYear, iMonth);this.iDay = checkDay(this.iYear, this.iMonth, iDay);}public LunarDate(int iYear, int iMonth) {super(iYear);this.iMonth = checkMonth(this.iYear, iMonth);}public LunarDate(int iYear) {super(iYear);}public LunarDate() {super();}public String toString() {String sCalendar = &农历&;sCalendar += sChineseNum[iYear / 1000]+ sChineseNum[iYear % 1000 / 100]+ sChineseNum[iYear % 100 / 10] + sChineseNum[iYear % 10] + &(&+ toChineseEra() + &)年&;if (iMonth & 12) {iMonth -= 12;sCalendar += &闰&;}if (iMonth == 12)sCalendar += &腊月&;else if (iMonth == 11)sCalendar += &冬月&;else if (iMonth == 1)sCalendar += &正月&;elsesCalendar += sChineseNum[iMonth] + &月&;if (iDay & 29)sCalendar += &三十&;else if (iDay &包含各类专业文献、专业论文、各类资格考试、生活休闲娱乐、高等教育、行业资料、54java 农历转阳历类等内容。 
 一个比较综合的阴历和阳历转换的java源程序_IT/计算机_专业资料。一个比较综合的阴历和阳历转换的java源程序一个比较综合的阴历和阳历的 java 源程序 /*** 阴历...  1 /2相关文档推荐 java(阳历转换为农历) 6页 1下载券 Java版农历和阳历转换源... 6页 1下载券 公历转农历 java 2页免费 PHP阳历到农历转换的一个...暂无...  ();//获取一个Calendar类的实 例对象 private String[] astr = { &星期一...c++万年历及公历农历转换... 8页 2下载券喜欢此文档的还喜欢 java万年历源代码...  比较常用并且比较简单的公历转换农历算法就是查表方法。 首先要保存公历农历的转换 信息:以任何一年作为起点,把从这一年起若干年的农历信息保存起来(在我的 C++类...  认农历、阳历、阴历、公历的差别_社会学_人文社科_专业资料。论农历、阳历、阴历、公历的差别现在人们生活中最常接触到的历法有两种: 一种为公元**年*月*日的形...  excel制作周历 农历阳历转换_IT/计算机_专业资料。农历阳历转换 自己制作周记事历 必备步骤一, 在 Excel 工作表界面下按&ALT+F11&组合键打开 VBA 窗口, 进入 VB...  4.设计类及对象设计 在本程序中:定义了一个 Simple_Calendar 类,主要定义一个...单片机 阴历阳历c算法 万... 6页 1下载券 Java万年历 21页 1下载券 java万...  2014 年农历阳历表
15:51:50 2014 年农历阳历表是介绍农历和阳历的对照表,包含 2014 年节日、2014 年节气等,而对于现 在的流年运势您则可以查阅...  //基于 1602 液晶显示的程序设计 #include&reg52.h& //C51 写的公历转农历和星期 #define uchar unsigned char #define uint unsigned int /* 公历年对应的...

我要回帖

更多关于 java农历转公历 的文章

 

随机推荐