万年历---java算法实现

合集下载

java控制台输出万年历

java控制台输出万年历

import java.util.Scanner;//蔡勒(Zeller)公式(只适合于1582年10月15日之后的情形):w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1//公式中的符号含义如下: c:世纪(年的高两位数); y:年(年的低两位数);//m:月(m大于等于3,小于等于14,即在蔡勒公式中,某年的1、2月要看作上一年的13、14月来计算,//比如2005年1月1日要看作2004年的13月1日来计算); d:日; []代表取整,即只要整数部分。

//w:星期;w对7取模得:0-星期日,1-星期一,2-星期二,3-星期三,4-星期四, 5-星期五,6-星期六//以2005年2月14日为例:c=20,y=4,m=14,d=14//w = 4 + [4/4] + [20/4] - 2*20 + [26*(14+1)/10] + 14 - 1 = 4 + 1 + 5 - 40 + 39 + 14 - 1 = 22//(除以7余1) 所以2005年2月14日是星期一。

public class PerpetualCalendarII {public static void main(String[] args) {// declare variable month,yearint month, monthDays = 0, year;int firstDayOfMonth, a, b, w;int count = 0;// declare flagboolean flag;Scanner sc = new Scanner(System.in);System.out.println("请输入年份:");year = sc.nextInt();System.out.println("请输入月份:");month = sc.nextInt();// judge year is leap year or notif ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { flag = true;} else {flag = false;}// get days of the monthswitch (month) {case 4:case 6:case 9:case 11:monthDays = 30;break;case 1:case 3:case 5:case 7:case 8:case 10:case 12:monthDays = 31;break;case 2:if (flag == true) {monthDays = 29;} else {monthDays = 28;}}// get the true yearif (month == 1) {month = 13;year -= 1;}if (month == 2) {month = 14;year -= 1;}// judge the firstDayOfMontha = year / 100;b = year % 100;// get the value of ww = b + (b / 4) + (a / 4) - 2 * a + 26 * (month + 1) / 10;if (w % 7 == 0) {firstDayOfMonth = 1;} else {firstDayOfMonth = w % 7;}System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");// output \tfor (int i = 0; i < firstDayOfMonth; i++) {System.out.print("\t");count++;}//loop daysfor (int i = 1; i <= monthDays; i++) {System.out.print(i + "\t");count++;if (count % 7 == 0) {System.out.println();}}}}。

Java万年历源代码,可显示公历、农历、系统时间、国际时间

Java万年历源代码,可显示公历、农历、系统时间、国际时间

import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar;import java.util.Locale;import java.util.TimeZone;public class wannianli extends JFrame implements ActionListener, MouseListener {private Calendar cld = Calendar.getInstance();//获取一个Calendar类的实例对象private String[] astr = { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };private DefaultTableModel dtm = new DefaultTableModel(null, astr);private JTable table = new JTable(dtm);private JScrollPane sp = new JScrollPane(table);private JButton bLastYear = new JButton("上一年");private JButton bNextYear = new JButton("下一年");private JButton bLastMonth = new JButton("上月");private JButton bNextMonth = new JButton("下月");private JPanel p1 = new JPanel(); // 设立八个中间容器,装入布局控制日期的按钮模块private JPanel p2 = new JPanel(new GridLayout(3,2));//网格布局private JPanel p3 = new JPanel(new BorderLayout());//边界布局private JPanel p4 = new JPanel(new GridLayout(2,1));private JPanel p5 = new JPanel(new BorderLayout());private JPanel p6 = new JPanel(new GridLayout(2,2));private JPanel p7 = new JPanel(new GridLayout(2,1));private JPanel p8 = new JPanel(new BorderLayout());private JComboBox timeBox = newJComboBox(TimeZone.getAvailableIDs());//对所有支持时区进行迭代,获取所有的id;private JTextField jtfYear = new JTextField(5);// jtfYeaar年份显示输入框private JTextField jtfMonth = new JTextField(2);// jtfMouth月份显示输入框private JTextField timeField=new JTextField();//各城市时间显示框private static JTextArea jta = new JTextArea(10,5);//农历显示区private JScrollPane jsp = new JScrollPane(jta);private JLabel l = new JLabel("花江小精灵:亲!你可以直接输入年月查询.");private JLabel lt = new JLabel();private JLabel ld = new JLabel();private JLabel lu = new JLabel("农历和节气");private JLabel null1=new JLabel();private int lastTime;//private String localTime = null;private String s = null;private SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy年MM月dd 日 hh时mm分ss秒");public wannianli() {super("花江日历过去仅留追忆,未来刚生憧憬,唯有坚守本心,把握今天 ZYT 詹永堂 ");// 框架命名this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 窗口关闭函数this.getContentPane().setLayout(new BorderLayout(9, 10));jta.setLineWrap(true);// 长度大于分配长度时候则换行jta.setFont(new Font("黑体", Font.BOLD, 16));table.setBackground(Color.white);table.setGridColor(Color.pink);// 星期之间的网格线是灰色的table.setBackground(Color.white);table.setColumnSelectionAllowed(true);// 将table中的列设置为可选择的table.setSelectionBackground(Color.pink);// 当选定某一天时背景颜色为黑色table.setSelectionForeground(Color.GREEN);table.setBackground(new Color(184,207, 229));// 日期显示表格为浅蓝色table.setFont(new Font("黑体", Font.BOLD, 24));// 日期数字字体格式table.setRowHeight(26);// 表格的高度table.addMouseListener(this); // 鼠标监听器、lu.setFont(new Font("黑体", Font.BOLD, 22));//农历标签格氏jtfYear.addActionListener(this);// 可输入年份的文本框// 为各个按钮添加监听函数bLastYear.addActionListener(this);bNextYear.addActionListener(this);bLastMonth.addActionListener(this);bNextMonth.addActionListener(this);timeBox.addItemListener(new TimeSelectedChangedListener());// 将按钮添加到Jpane上p1.add(bLastYear);p1.add(jtfYear);// 年份输入文本框p1.add(bNextYear);p1.add(bLastMonth);p1.add(jtfMonth);p1.add(bNextMonth);p3.add(jsp, BorderLayout.SOUTH);p3.add(lu,BorderLayout.CENTER);p3.add(ld, BorderLayout.NORTH);p4.add(lt);p4.add(l);p5.add(p4, BorderLayout.SOUTH);p5.add(sp, BorderLayout.CENTER);p5.add(p1, BorderLayout.NORTH);p6.add(timeBox);p6.add(null1);p6.add(timeField);p8.add(p2,BorderLayout.CENTER);p8.add(p7,BorderLayout.SOUTH);this.getContentPane().add(p3, BorderLayout.EAST);this.getContentPane().add(p5, BorderLayout.CENTER);this.getContentPane().add(p6,BorderLayout.SOUTH);this.getContentPane().add(p8,BorderLayout.WEST);String[] strDate = DateFormat.getDateInstance().format(new Date()) .split("-");// 获取日期cld.set(Integer.parseInt(strDate[0]), Integer.parseInt(strDate[1]) - 1,0);showCalendar(Integer.parseInt(strDate[0]),Integer.parseInt(strDate[1]), cld);jtfMonth.setEditable(false);// 设置月份文本框为不可编辑jtfYear.setText(strDate[0]);jtfMonth.setText(strDate[1]);this.showTextArea(strDate[2]);ld.setFont(new Font("新宋体", Font.BOLD, 24));new Timer(lt).start();new TimeThread().start();this.setBounds(200, 200, 700, 350);this.setResizable(false);this.setVisible(true);}public void showCalendar(int localYear, int localMonth, Calendar cld) {int Days = getDaysOfMonth(localYear, localMonth) +cld.get(Calendar.DAY_OF_WEEK) -2;Object [] ai = new Object[7];lastTime = 0;for (int i = cld.get(Calendar.DAY_OF_WEEK)-1; i <= Days; i++) {ai[i%7] =String.valueOf(i-(cld.get(Calendar.DAY_OF_WEEK)-2));if (i%7 == 6){dtm.addRow(ai);ai = new Object[7];lastTime++;}}dtm.addRow(ai);}public int getDaysOfMonth(int Year, int Month) {//计算各月的天数if(Month==1||Month==3||Month==5||Month==7||Month==8||Month==10||Mont h==12){return 31;}if(Month==4||Month==6||Month==9||Month==11){return 30;}if(Year%4==0&&Year%100!=0||Year%400==0)//闰年{return 29;}else {return 28;}}public void actionPerformed(ActionEvent e)//从界面上获取年月数据{if(e.getSource() == jtfYear || e.getSource() == bLastYear || e.getSource() == bNextYear ||e.getSource() == bLastMonth || e.getSource() == bNextMonth){int m, y;try//控制输入的年份正确,异常控制{if (jtfYear.getText().length() != 4){throw new NumberFormatException();}y = Integer.parseInt(jtfYear.getText());m = Integer.parseInt(jtfMonth.getText());}catch (NumberFormatException ex){JOptionPane.showMessageDialog(this, "请输入4位0-9的数字!", "年份有误", JOptionPane.ERROR_MESSAGE);return;}ld.setText("没有选择日期");for (int i = 0; i < lastTime+1; i++){ dtm.removeRow(0);}if(e.getSource() ==bLastYear){ jtfYear.setText(String.valueOf(--y)); }if(e.getSource() ==bNextYear){jtfYear.setText(String.valueOf(++y)); }if(e.getSource() == bLastMonth){if(m == 1){jtfYear.setText(String.valueOf(--y));m = 12;jtfMonth.setText(String.valueOf(m));}else{jtfMonth.setText(String.valueOf(--m));}}if(e.getSource() == bNextMonth){if(m == 12){jtfYear.setText(String.valueOf(++y));m = 1;jtfMonth.setText(String.valueOf(m));}else{jtfMonth.setText(String.valueOf(++m));}}cld.set(y, m-1, 0);showCalendar(y, m, cld);}}public void mouseClicked(MouseEvent e){jta.setText(null);int r = table.getSelectedRow();int c = table.getSelectedColumn();if (table.getValueAt(r,c) == null){ld.setText("没有选择日期");}else{this.showTextArea(table.getValueAt(r,c));}}private void showTextArea(Object selected){ld.setText(jtfYear.getText()+"年"+jtfMonth.getText()+"月"+selected+"日");}public static void main(String[] args){JFrame.setDefaultLookAndFeelDecorated(true);JDialog.setDefaultLookAndFeelDecorated(true);new wannianli();jta.setText(today());}private void updateTimeText(String timeZoneId) {if(timeZoneId != null){TimeZone timeZone = TimeZone.getTimeZone(timeZoneId);dateFormat.setTimeZone(timeZone);Calendar calendar = Calendar.getInstance();calendar.setTimeZone(timeZone);timeField.setText(dateFormat.format(calendar.getTime()));}else{timeField.setText(null);}}private class TimeSelectedChangedListener implements ItemListener { public void itemStateChanged(ItemEvent e) {if (e.getStateChange()==ItemEvent.SELECTED) {if (e.getItem() instanceof String) {s = e.getItem().toString();}}}}private class TimeThread extends Thread{public void run(){while(true){updateTimeText(s);try{Thread.sleep(100);}catch(InterruptedException e){e.printStackTrace();}}}}class Timer extends Thread //显示系统时间{private JLabel lt;private SimpleDateFormat fy = new SimpleDateFormat(" Gyyyy.MM.dd HH:mm:ss ");public Timer(JLabel lt){this.lt=lt;}public void run(){while(true){try{lt.setText(fy.format(new Date()));this.sleep(500);}catch(InterruptedException ex){ex.printStackTrace();}}}}final private 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 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 };public 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年的总天数final private static int lYearDays(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;elsereturn 29;} elsereturn 0;}// 传回农历 y年闰哪个月 1-12 , 没闰传回 0final 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;elsereturn 30;}// 传回农历 y年的生肖final public static String AnimalsYear(int y) {return Animals[(y - 4) % 12];}//传入月日的offset 传回干支,0=甲子final private static String cyclicalm(int num) {return (Gan[num % 10] + Zhi[num % 12]);}// 传入 offset 传回干支, 0=甲子final public static String cyclical(int y) {int num = y - 1900 + 36;return (cyclicalm(num));}// 传出农历.year0 .month1 .day2 .yearCyl3 .monCyl4 .dayCyl5 .isLeap6final private long[] Lunar(int y, int m) {long[] nongDate = new long[7];int i = 0, temp = 0, leap = 0;Date baseDate = new GregorianCalendar(1900 + 1900, 1,31).getTime();Date objDate = new GregorianCalendar(y + 1900, m, 1).getTime();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;}// 传出y年m月d日对应的农历.year0 .month1 .day2 .yearCyl3 .monCyl4 .dayCyl5 .isLeap6final 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 GregorianCalendar(0 + 1900, 0, 31).getTime();Date objDate = new GregorianCalendar(y, m - 1, d).getTime();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 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)a = "初";if (two == 1)a = "十";if (two == 2)a = "廿";if (two == 3)a = "三";int one = (int) (day % 10);switch (one) {case 1:a += "一";break;case 2:a += "二";break;case 3:a += "三";break;case 4:a += "四";break;case 5:a += "五";break;case 6:a += "六";break;case 7:a += "七";break;case 8:a += "八";break;case 9:a += "九";break;}return a;}public static String 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);StringBuffer sToday = new StringBuffer();try {sToday.append(sdf.format(today.getTime()));sToday.append(" \n");sToday.append(" \n");sToday.append(" \n");sToday.append(" 农历");sToday.append(cyclical(year));sToday.append('(');sToday.append(AnimalsYear(year));sToday.append(")年");sToday.append(" \n");sToday.append(" ");sToday.append(nStr1[(int) l[1]]);sToday.append("月");sToday.append(getChinaDate((int) (l[2])));return sToday.toString();} finally {sToday = null;}}private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy 年M月d日 EEEEE");public void mouseEntered(MouseEvent e) {}public void mouseExited(MouseEvent e) {}public void mousePressed(MouseEvent e) {}public void mouseReleased(MouseEvent e) { }}。

毕业设计基于javagui的万年历系统的设计与实现[管理资料]

毕业设计基于javagui的万年历系统的设计与实现[管理资料]

目录1 需求分析 (3)2 总体设计 (3)设计的总体思想与算法描述 (4)模块结构图 (5)用户查询主界面设计模块 (5)用户输入查询日历模块 (5)农历与公历日期信息转换模块 (6)相应日期节日信息显示模块 (7)查询主界面效果更换模块 (7)各模块的功能与处理流程描述 (8)用户查询主界面设计模块功能和处理流程 (8)用户输入查询日历模块 (9)公历和农历日期信息转换模块 (9)相应日期节日信息显示模块 (9)查询主界面效果更换模块 (10)界面设计 (10)万年历初始化界面 (10)特定的日期查询界面 (11)特定的日期节日显示界面(如春节、元宵节) (12)特定的农历和公历日期信息转换界面 (13)查询主界面换肤功能展示界面 (14)3 各功能模块程序设计 (16)查询主界面布局设计部分截取代码 (16)公历日期求解算法程序截取代码 (18)农历与公历转换算法程序截取代码 (21)节日求解算法程序实现截取代码 (26)4 小结 (28)5 参考文献 (29)题目:基于Java GUI 的万年历系统的设计与实现开发平台:eclipse1 需求分析本系统所描述的万年历系统主要是基于Java GUI 来实现的。

其主要功能是致力于为用户提供方便快捷、准确的日历时间信息,以便用户能够迅速地查找出自己所需的相关日历信息。

本万年历系统主要的功能和任务是任意选择一段时间内的某个年份月份进行查询,对相关的日历信息进行公历和农历的换算显示,显示相应日期的节日信息等。

功能描述:(1)日历查询实现:主要通过主界面顶端的两个下拉列表框来选择相应待查询的年份和月份以实现具体的月份的日历查询。

(2)公历和农历的时间换算:当把鼠标指针指向日历表里的某个具体日期数字上时,会自动显示相关的农历年份、月份、和生肖的相关信息。

(3)节日信息的显示:当某个日期为某个特定的节日时,相应的日期数字所在表格会显示该节日信息,包括了阳历和农历节日。

java中如何获取当前年份的第一天和最后一天

java中如何获取当前年份的第一天和最后一天

java中如何获取当前年份的第⼀天和最后⼀天package com.dada.test;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;public class DateUtil {/*** 默认⽇期格式*/public static String DEFAULT_FORMAT = "yyyy-MM-dd";/*** 测试主⽅法* @param args*/public static void main(String[] args) {for(int i = 1951;i < 1960;i++){System.out.println(formatDate(getYearFirst(i)));System.out.println(formatDate(getYearLast(i)));}System.out.println(formatDate(getCurrYearFirst()));System.out.println(formatDate(getCurrYearLast()));}/*** 格式化⽇期* @param date ⽇期对象* @return String ⽇期字符串*/public static String formatDate(Date date){SimpleDateFormat f = new SimpleDateFormat(DEFAULT_FORMAT);String sDate = f.format(date);return sDate;}/*** 获取当年的第⼀天* @param year* @return*/public static Date getCurrYearFirst(){Calendar currCal=Calendar.getInstance();int currentYear = currCal.get(Calendar.YEAR);return getYearFirst(currentYear);}/*** 获取当年的最后⼀天* @param year* @return*/public static Date getCurrYearLast(){Calendar currCal=Calendar.getInstance();int currentYear = currCal.get(Calendar.YEAR);return getYearLast(currentYear);}/*** 获取某年第⼀天⽇期* @param year 年份* @return Date*/public static Date getYearFirst(int year){Calendar calendar = Calendar.getInstance();calendar.clear();calendar.set(Calendar.YEAR, year);Date currYearFirst = calendar.getTime();return currYearFirst;}/*** 获取某年最后⼀天⽇期* @param year 年份* @return Date*/public static Date getYearLast(int year){Calendar calendar = Calendar.getInstance(); calendar.clear();calendar.set(Calendar.YEAR, year);calendar.roll(Calendar.DAY_OF_YEAR, -1); Date currYearLast = calendar.getTime();return currYearLast;}}。

java万年历源代码(可运行)

java万年历源代码(可运行)
private JTable table = new JTable(dtm); //装日期的表格
private JScrollPane sp = new JScrollPane(table);
private JButton bLastYear = new JButton("上一年");
p3.add(jsp, BorderLayout.CENTER);
p3.add(p2, BorderLayout.SOUTH);
p3.add(ld, BorderLayout.NORTH);
private JTextArea jta = new JTextArea(); //jta--JTextArea
private JScrollPane jsp = new JScrollPane(jta);
private JLabel l = new JLabel("年份文本框中可直接键入要查找的年份,以提高查询效率");
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
//import java.sql.Date;
cld.set(Integer.parseInt(strDate[0]), Integer.parseInt(strDate[1])-1, 0);
showCalendar(Integer.parseInt(strDate[0]), Integer.parseInt(strDate[1]), cld);

java获取年月日的方法

java获取年月日的方法

Java获取年月日的方法在Java编程中,我们经常需要获取当前的年、月和日。

这些信息在许多应用程序中都是必需的,例如日历应用、日期处理和数据分析等。

本文将介绍几种获取年月日的方法,帮助你在Java中轻松地处理日期。

1. 使用Java.util.Date类Java.util.Date类是Java中处理日期和时间的基本类之一。

要获取当前的年、月和日,可以使用以下代码:import java.util.Date;import java.text.SimpleDateFormat;public class Main {public static void main(String[] args) {Date date = new Date();SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");SimpleDateFormat sdfMonth = new SimpleDateFormat("MM");SimpleDateFormat sdfDay = new SimpleDateFormat("dd");String year = sdfYear.format(date);String month = sdfMonth.format(date);String day = sdfDay.format(date);System.out.println("Year: " + year);System.out.println("Month: " + month);System.out.println("Day: " + day);}}在上面的代码中,我们使用了SimpleDateFormat类来格式化日期。

通过传入不同的格式化模式,我们可以获取所需的日期部分。

万年历程序

万年历程序

万年历程序简介万年历(Perpetual Calendar)是一个可以显示公历和农历的时间工具。

在这个文档中,我们将讨论如何编写一个简单的万年历程序,以及其实现原理和功能。

功能该万年历程序将具备以下功能:1.显示当前日期2.显示当前周数3.显示当前月份的日历4.显示指定年份和月份的日历实现原理为了实现万年历程序,我们需要使用一些基本的计算方法。

以下是一些相关的计算原理:判断某年是否是闰年判断某年是否是闰年可以使用以下公式:is_leap_year = (year % 4 == 0 and year % 100 ! = 0) or (year % 400 == 0)若上述公式的值为真,则表示该年份是闰年。

计算指定年份和月份的天数可以使用以下公式来计算指定年份和月份的天数:days_in_month = [31, # 1月28 + is_leap_year, # 2月31, # 3月30, # 4月31, # 5月30, # 6月31, # 7月31, # 8月30, # 9月31, # 10月30, # 11月31 # 12月]这样,我们就可以得到每个月份的天数。

判断某年某月的第一天是星期几我们可以使用Zeller’s Congruence算法来判断某年某月的第一天是星期几。

以下是该算法的公式:h = (day + 26*(month+1)//10 + k + k//4 + j//4 + 5*j) % 7其中,h是星期几(0代表星期六,1代表星期日,依次类推),day是月份的第一天的日期,month是月份(3代表三月,4代表四月,依次类推),k是该年的前两位数,j是该年的后两位数。

实现步骤以下是实现万年历程序的步骤:1.获取当前日期和时间2.使用相关公式判断当前年份是否是闰年3.显示当前日期和时间4.计算当前周数并显示5.获取当前月份的相关信息:年份、月份、天数、星期几6.显示当前月份的日历7.提供用户界面,允许用户输入指定的年份和月份8.使用相关算法计算指定年份和月份的日历9.显示指定年份和月份的日历示例代码以下是使用Python语言实现的一个简单的万年历程序:```python import datetime获取当前日期today = datetime.date.today() current_year = today.year current_month = today.month current_day = today.day判断当前年份是否是闰年is_leap_year = (current_year % 4 == 0 and current_year % 100 != 0) or (current_year % 400 == 0)显示当前日期和时间print(。

java万年历程序代码

java万年历程序代码

package pack;import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Calendar;import java.util.Date;public class rili extends JFrame implements ActionListener { JButton b_today, b_query;JLabel lb_Year, lb_Month;JButton b_week[] = new JButton[7];JButton b_day[][] = new JButton[6][7];Container thisContainer;JPanel pUp;JPanel pCenter;JPanel pCenter_week, pCenter_day;JComboBox year, month;public void init() {b_today = new JButton("Today");b_query = new JButton("Query");setTitle("日历");lb_Year = new JLabel("Year");lb_Month = new JLabel("Month");year = new JComboBox();month = new JComboBox();setDate();pUp = new JPanel();pUp.add(lb_Year);pUp.add(year);pUp.add(lb_Month);pUp.add(month);pUp.add(b_today);pUp.add(b_query);b_today.addActionListener(this);b_query.addActionListener(this);pCenter = new JPanel();pCenter_week = new JPanel();b_week[0] = new JButton("星期日");b_week[1] = new JButton("星期一");b_week[2] = new JButton("星期二");b_week[3] = new JButton("星期三");b_week[4] = new JButton("星期四");b_week[5] = new JButton("星期五");b_week[6] = new JButton("星期六");b_week[0].setSize(400, 200);b_week[1].setSize(400, 200);b_week[2].setSize(400, 200);b_week[3].setSize(400, 200);b_week[4].setSize(400, 200);b_week[5].setSize(400, 200);b_week[6].setSize(400, 200);for (int i = 0; i < 7; i++) {b_week[i].setEnabled(false);pCenter_week.add(b_week[i]);}pCenter_day = new JPanel();for (int cols = 0; cols < 6; cols++) {for (int rows = 0; rows < 7; rows++) {b_day[cols][rows] = new JButton("");b_day[cols][rows].setSize(400, 200);this.pCenter_day.add(b_day[cols][rows]);}}pCenter_day.setLayout(new GridLayout(6, 7));setDay(Integer.parseInt(this.year.getSelectedItem().toString()),Integer.parseInt(this.month.getSelectedItem().toString()));// setDay(2011,2);pCenter.setLayout(new BorderLayout());pCenter.add(pCenter_week, "North");pCenter.add(pCenter_day, "Center");thisContainer = this.getContentPane();thisContainer.setLayout(new BorderLayout());thisContainer.add(pUp, "North");thisContainer.add(pCenter, "Center");this.setVisible(true);this.setResizable(false);this.pack();}public void setDate() {int year, month, day, week;Calendar cal = Calendar.getInstance();year = cal.get(Calendar.YEAR);month = cal.get(Calendar.MONTH);day = cal.get(Calendar.DA TE);week = cal.get(Calendar.WEEK_OF_YEAR);int year_temp = year - 4;for (int i = 0; i < 10; i++) {this.year.addItem(year_temp);year_temp += 1;}this.year.setSelectedIndex(4);for (int n = 0; n < 12; n++) {this.month.addItem(n + 1);}this.month.setSelectedIndex(month);}public void setDay(int Year, int Month) {int count;Calendar c = Calendar.getInstance();c.clear();c.set(Year, Month-1, 1);count = c.getActualMaximum(Calendar.DAY_OF_MONTH); // 总天数System.out.print(count);int day = c.get(Calendar.DAY_OF_WEEK) - 1; // 0为星期天,6为星期六System.out.print(day);int i = 1 - day;for (int cols = 0; cols < 6; cols++) {for (int rows = 0; rows < 7; rows++) {String st = String.valueOf(i);b_day[cols][rows].setText(st);b_day[cols][rows].setEnabled(false);if (i > 0 && i <= count)b_day[cols][rows].setVisible(true);elseb_day[cols][rows].setVisible(false);i++;}}}public void actionPerformed(ActionEvent e) {if (e.getSource() == b_query) {this.setDay(Integer.parseInt(this.year.getSelectedItem().toString()), Integer.parseInt(this.month.getSelectedItem().toString()));}if (e.getSource() == b_today) {int year, month;Calendar cal = Calendar.getInstance();year = cal.get(Calendar.YEAR);month = cal.get(Calendar.MONTH)+1;this.setDay(year,month);}}public static void main(String[] args) {rili rl = new rili();rl.init();}}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

万年历---java算法实现万年历是我在网上见到的一份极高高精度的万年历,其采用先进的算法实现,其精度堪比刘安国教授为中国科学院国家授时中心制作的日梭万年历。

但网络上只有javascript 版本。

于是自己将其翻译为java程序,并公布于此,方便大家使用。

本文中讲的万年历是一款采用现代天文算法制作的农历历算程序,含有公历与回历信息,可以很方便的进行公、农、回三历之间的转换。

提供公元-4712年到公元9999年的日期查询功能。

其中1500年到1940农历数据已经与陈垣的《二十史朔闰表》核对;含有从公420元(南北朝/宋武帝元年)到今的基本年号。

在过去几百年中,寿星万年历的误差是非常小的,节气时刻计算及日月合朔时刻的平均误差小于1秒,太阳坐标的最大可能误差为0.2角秒,月亮坐标的最大可能误差为3角秒,平均误差为误差的1/6。

万年历中含有几百个国内城市的经纬度,并且用户可根据自已的需要扩展经纬度数据。

代码如下:/*** @author lxslove* @mail moodlxs at 163**/public class SolarTerm {// ========角度变换===============private static final double rad = 180 * 3600 / Math.PI; // 每弧度的角秒数private static final double RAD = 180 / Math.PI; // 每弧度的角度数// ================日历计算===============private static final double J2000 = 2451545; // 2000年前儒略日数(2000-1-1// 12:00:00格林威治平时)// =========黄赤交角及黄赤坐标变换===========private static final double hcjjB[] = { 84381.448, -46.8150, -0.00059,0.001813 };// 黄赤交角系数表private static final double preceB[] = { 0, 50287.92262, 111.24406,0.07699, -0.23479, -0.00178, 0.00018, 0.00001 };// Date黄道上的岁差pprivate double Y = 2000;private double M = 1;private double D = 1;private double h = 12;private double m = 0;private double s = 0;private static final double[] dts = {// 世界时与原子时之差计算表-4000, 108371.7, -13036.80, 392.000, 0.0000, -500, 17201.0,-627.82, 16.170, -0.3413, -150, 12200.6, -346.41, 5.403, -0.1593, 150, 9113.8, -328.13, -1.647, 0.0377, 500, 5707.5, -391.41, 0.915, 0.3145, 900, 2203.4, -283.45, 13.034, -0.1778, 1300, 490.1, -57.35, 2.085, -0.0072, 1600, 120.0, -9.81, -1.532, 0.1403, 1700, 10.2,-0.91, 0.510, -0.0370, 1800, 13.4, -0.72, 0.202, -0.0193, 1830,7.8, -1.81, 0.416, -0.0247, 1860, 8.3, -0.13, -0.406, 0.0292, 1880, -5.4, 0.32, -0.183, 0.0173, 1900, -2.3, 2.06, 0.169, -0.0135, 1920, 21.2, 1.69, -0.304, 0.0167, 1940, 24.2, 1.22, -0.064, 0.0031, 1960, 33.2, 0.51, 0.231, -0.0109, 1980, 51.0, 1.29, -0.026, 0.0032, 2000, 64.7, -1.66, 5.224, -0.2905, 2150, 279.4, 732.95, 429.579, 0.0158, 6000 };// 取整数部分public static double int2(double v) {v = Math.floor(v);if (v < 0)return v + 1;return v;}// 对超过0-2PI的角度转为0-2PIpublic static double rad2mrad(double v) {v = v % (2 * Math.PI);if (v < 0)return v + 2 * Math.PI;return v;}// 计算世界时与原子时之差,传入年public double deltatT(double y) {int i = 0;for (i = 0; i < 100; i += 5)if (y < dts[i + 5] || i == 95)break;double t1 = (y - dts[i]) / (dts[i + 5] - dts[i]) * 10;double t2 = t1 * t1;double t3 = t2 * t1;return dts[i + 1] + dts[i + 2] * t1 + dts[i + 3] * t2 + dts[i + 4] * t3;}// 传入儒略日(J2000起算),计算UTC与原子时的差(单位:日)public double deltatT2(double jd) {return this.deltatT(jd / 365.2425 + 2000) / 86400.0;}// 公历转儒略日,UTC=1表示原日期是UTCpublic double toJD(boolean UTC) {double y = this.Y; // 取出年月double m = this.M;double n = 0;if (m <= 2) {m += 12;y--;}if (this.Y * 372 + this.M * 31 + this.D >= 588829) {// 判断是否为格里高利历日1582*372+10*31+15n = int2(y / 100);n = 2 - n + int2(n / 4);// 加百年闰}n += int2(365.2500001 * (y + 4716)); // 加上年引起的偏移日数n += int2(30.6 * (m + 1)) + this.D; // 加上月引起的偏移日数及日偏移数 n += ((this.s / 60 + this.m) / 60 + this.h) / 24 - 1524.5;if (UTC)return n + this.deltatT2(n - J2000);}// 儒略日数转公历,UTC=1表示目标公历是UTCpublic void setFromJD(double jd, boolean UTC) {if (UTC)jd -= this.deltatT2(jd - J2000);jd += 0.5;// 取得日数的整数部份A及小数部分Fdouble A = int2(jd);double F = jd - A;double D;if (A > 2299161) {D = int2((A - 1867216.25) / 36524.25);A += 1 + D - int2(D / 4);}A += 1524; // 向前移4年零2个月this.Y = int2((A - 122.1) / 365.25);// 年D = A - int2(365.25 * this.Y); // 去除整年日数后余下日数this.M = int2(D / 30.6001); // 月数this.D = D - int2(this.M * 30.6001);// 去除整月日数后余下日数 this.Y -= 4716;this.M--;if (this.M > 12)this.M -= 12;if (this.M <= 2)this.Y++;// 日的小数转为时分秒F *= 24;this.h = int2(F);F -= this.h;F *= 60;this.m = int2(F);F -= this.m;F *= 60;}// 设置时间,参数例:"20000101 120000"或"20000101"public void setFromStr(String s) {this.Y = Double.parseDouble(s.substring(0, 4));this.M = Double.parseDouble(s.substring(4, 2));this.D = Double.parseDouble(s.substring(6, 2));this.h = Double.parseDouble(s.substring(9, 2));this.m = Double.parseDouble(s.substring(11, 2));this.s = Double.parseDouble(s.substring(13, 2)); /* 将5改为了2 */ }// 日期转为串public String toStr() {String Y = " " + (int)this.Y;String M = "0" + (int)this.M;String D = "0" + (int)this.D;double h = this.h, m = this.m, s = Math.floor(this.s + .5);if (s >= 60) {s -= 60;m++;}if (m >= 60) {m -= 60;h++;}String sh = "0" + (int)h, sm = "0" + (int)m, ss = "0" + (int)s;Y = Y.substring(Y.length() - 5, Y.length());M = M.substring(M.length() - 2, M.length());D = D.substring(D.length() - 2, D.length());sh = sh.substring(sh.length() - 2, sh.length());sm = sm.substring(sm.length() - 2, sm.length());ss = ss.substring(ss.length() - 2, ss.length());return Y + "-" + M + "-" + D + " " + sh + ":" + sm + ":" + ss;}// 算出:jd转到当地UTC后,UTC日数的整数部分或小数部分// 基于J2000力学时jd的起算点是12:00:00时,所以跳日时刻发生在12:00:00,这与日历计算发生矛盾// 把jd改正为00:00:00起算,这样儒略日的跳日动作就与日期的跳日同步// 改正方法为jd=jd+0.5-deltatT+shiqu/24// 把儒略日的起点移动-0.5(即前移12小时)// 式中shiqu是时区,北京的起算点是-8小时,shiqu取8public double Dint_dec(double jd, int shiqu, boolean dec) {double u = jd + 0.5 - this.deltatT2(jd) + shiqu / 24;if (dec)return Math.floor(u); // 返回整数部分elsereturn u - Math.floor(u); // 返回小数部分}// 计算两个日期的相差的天数,输入字串格式日期,如:"20080101"double d1_d2(String d1, String d2) {double Y = this.Y, M = this.M, D = this.D, h = this.h, m = this.m, s = this.s; // 备份原来的数据this.setFromStr(d1.substring(0, 8) + " 120000");double jd1 = this.toJD(false);this.setFromStr(d2.substring(0, 8) + " 120000");double jd2 = this.toJD(false);this.Y = Y;this.M = M;this.D = D;this.h = h;this.m = m;this.s = s; // 还原if (jd1 > jd2)return Math.floor(jd1 - jd2 + .0001);elsereturn -Math.floor(jd2 - jd1 + .0001);}// 返回黄赤交角(常规精度),短期精度很高public static double hcjj1(double t) {double t1 = t / 36525;double t2 = t1 * t1;double t3 = t2 * t1;return (hcjjB[0] + hcjjB[1] * t1 + hcjjB[2] * t2 + hcjjB[3] * t3) / rad;}// 黄赤转换(黄赤坐标旋转)public static void HCconv(double[] JW, double E) {// 黄道赤道坐标变换,赤到黄E取负double HJ = rad2mrad(JW[0]), HW = JW[1];double sinE = Math.sin(E), cosE = Math.cos(E);double sinW = cosE * Math.sin(HW) + sinE * Math.cos(HW) * Math.sin(HJ); double J = Math.atan2(Math.sin(HJ) * cosE - Math.tan(HW) * sinE, Math.cos(HJ));JW[0] = rad2mrad(J);JW[1] = Math.asin(sinW);}// 补岁差public static void addPrece(double jd, double[] zb) {int i;double t = 1, v = 0, t1 = jd / 365250;for (i = 1; i < 8; i++) {t *= t1;v += preceB[i] * t;}zb[0] = rad2mrad(zb[0] + (v + 2.9965 * t1) / rad);}// ===============光行差==================private static final double GXC_e[] = { 0.016708634, -0.000042037,-0.0000001267 }; // 离心率private static final double GXC_p[] = { 102.93735 / RAD, 1.71946 / RAD,0.00046 / RAD }; // 近点private static final double GXC_l[] = { 280.4664567 / RAD,36000.76982779 / RAD, 0.0003032028 / RAD, 1 / 49931000 / RAD,-1 / 153000000 / RAD }; // 太平黄经private static final double GXC_k = 20.49552 / rad; // 光行差常数// 恒星周年光行差计算(黄道坐标中)public static void addGxc(double t, double[] zb) {double t1 = t / 36525;double t2 = t1 * t1;double t3 = t2 * t1;double t4 = t3 * t1;double L = GXC_l[0] + GXC_l[1] * t1 + GXC_l[2] * t2 + GXC_l[3] * t3+ GXC_l[4] * t4;double p = GXC_p[0] + GXC_p[1] * t1 + GXC_p[2] * t2;double e = GXC_e[0] + GXC_e[1] * t1 + GXC_e[2] * t2;double dL = L - zb[0], dP = p - zb[0];zb[0] -= GXC_k * (Math.cos(dL) - e * Math.cos(dP)) / Math.cos(zb[1]);zb[1] -= GXC_k * Math.sin(zb[1]) * (Math.sin(dL) - e * Math.sin(dP));zb[0] = rad2mrad(zb[0]);}// ===============章动计算==================private static final double nutB[] = {// 章动表2.1824391966, -33.757045954, 0.0000362262, 3.7340E-08, -2.8793E-10, -171996, -1742, 92025, 89, 3.5069406862, 1256.663930738,0.0000105845, 6.9813E-10, -2.2815E-10, -13187, -16, 5736, -31,1.3375032491, 16799.418221925, -0.0000511866, 6.4626E-08,-5.3543E-10, -2274, -2, 977, -5, 4.3648783932, -67.514091907,0.0000724525, 7.4681E-08, -5.7586E-10, 2062, 2, -895, 5,0.0431251803, -628.301955171, 0.0000026820, 6.5935E-10, 5.5705E-11, -1426, 34, 54, -1, 2.3555557435, 8328.691425719, 0.0001545547,2.5033E-07, -1.1863E-09, 712, 1, -7, 0,3.4638155059,1884.965885909, 0.0000079025, 3.8785E-11, -2.8386E-10, -517, 12,224, -6, 5.4382493597, 16833.175267879, -0.0000874129, 2.7285E-08, -2.4750E-10, -386, -4, 200, 0, 3.6930589926, 25128.109647645,0.0001033681, 3.1496E-07, -1.7218E-09, -301, 0, 129, -1,3.5500658664, 628.361975567, 0.0000132664, 1.3575E-09, -1.7245E-10, 217, -5, -95, 3 };public static class ZD {public double Lon;public double Obl;}// 计算黄经章动及交角章动public static ZD nutation(double t) {ZD d = new ZD();d.Lon = 0;d.Obl = 0;t /= 36525;double c, t1 = t, t2 = t1 * t1, t3 = t2 * t1, t4 = t3 * t1;// t5=t4*t1;for (int i = 0; i < nutB.length; i += 9) {c = nutB[i] + nutB[i + 1] * t1 + nutB[i + 2] * t2 + nutB[i + 3]* t3 + nutB[i + 4] * t4;d.Lon += (nutB[i + 5] + nutB[i + 6] * t / 10) * Math.sin(c); // 黄经章动d.Obl += (nutB[i + 7] + nutB[i + 8] * t / 10) * Math.cos(c); // 交角章动}d.Lon /= rad * 10000; // 黄经章动d.Obl /= rad * 10000; // 交角章动return d;}// 本函数计算赤经章动及赤纬章动public static void nutationRaDec(double t, double[] zb) {double Ra = zb[0], Dec = zb[1];double E = hcjj1(t), sinE = Math.sin(E), cosE = Math.cos(E); // 计算黄赤交角 ZD d = nutation(t); // 计算黄经章动及交角章动double cosRa = Math.cos(Ra), sinRa = Math.sin(Ra);double tanDec = Math.tan(Dec);zb[0] += (cosE + sinE * sinRa * tanDec) * d.Lon - cosRa * tanDec* d.Obl; // 赤经章动zb[1] += sinE * cosRa * d.Lon + sinRa * d.Obl; // 赤纬章动zb[0] = rad2mrad(zb[0]);}//=================以下是月球及地球运动参数表=================== /**************************************** 如果用记事本查看此代码,请在"格式"菜单中去除"自动换行"* E10是关于地球的,格式如下:* 它是一个数组,每3个数看作一条记录,每条记录的3个数记为A,B,C* rec=A*cos(B+C*t); 式中t是J2000起算的儒略千年数* 每条记录的计算结果(即rec)取和即得地球的日心黄经的周期量L0* E11格式如下: rec = A*cos*(B+C*t) *t, 取和后得泊松量L1* E12格式如下: rec = A*cos*(B+C*t) *t*t, 取和后得泊松量L2* E13格式如下: rec = A*cos*(B+C*t) *t*t*t, 取和后得泊松量L3* 最后地球的地心黄经:L = L0+L1+L2+L3+...* E20,E21,E22,E23...用于计算黄纬* M10,M11等是关于月球的,参数的用法请阅读Mnn()函数*****************************************///地球运动VSOP87参数private static final double E10[] = { //黄经周期项1.75347045673, 0.00000000000, 0.0000000000, 0.03341656456,4.66925680417, 6283.0758499914, 0.00034894275, 4.62610241759,12566.1516999828, 0.00003417571, 2.82886579606, 3.5231183490,0.00003497056, 2.74411800971, 5753.3848848968, 0.00003135896, 3.62767041758, 77713.7714681205, 0.00002676218,4.41808351397, 7860.4193924392, 0.00002342687,6.135********, 3930.2096962196,0.00001273166, 2.0370*******, 529.6909650946, 0.00001324292, 0.74246356352, 11506.7697697936, 0.00000901855,2.0450*******, 26.2983197998, 0.00001199167, 1.10962944315, 1577.3435424478,0.00000857223, 3.50849156957, 398.1490034082, 0.00000779786,1.178********, 5223.6939198022, 0.00000990250,5.23268129594, 5884.9268465832, 0.00000753141,2.53339053818, 5507.5532386674,0.00000505264, 4.58292563052, 18849.2275499742, 0.00000492379,4.20506639861, 775.5226113240, 0.00000356655,2.91954116867, 0.0673103028, 0.00000284125, 1.89869034186, 796.2980068164, 0.00000242810, 0.34481140906, 5486.7778431750, 0.00000317087, 5.84901952218, 11790.6290886588, 0.00000271039, 0.31488607649,10977.0788046990, 0.00000206160, 4.80646606059, 2544.3144198834,0.00000205385, 1.86947813692, 5573.1428014331, 0.00000202261,2.45767795458, 6069.7767545534, 0.00000126184,1.0830*******, 20.7753954924, 0.00000155516, 0.83306073807, 213.2990954380, 0.00000115132, 0.64544911683, 0.9803210682, 0.00000102851,0.63599846727, 4694.0029547076, 0.00000101724,4.26679821365, 7.1135470008, 0.00000099206, 6.20992940258, 2146.1654164752, 0.00000132212, 3.41118275555, 2942.4634232916, 0.00000097607,0.68101272270, 155.4203994342, 0.00000085128,1.29870743025, 6275.9623029906, 0.00000074651,1.75508916159, 5088.6288397668,0.00000101895, 0.97569221824, 15720.8387848784, 0.00000084711,3.67080093025, 71430.6956181291, 0.00000073547,4.67926565481, 801.8209311238, 0.00000073874,3.50319443167, 3154.6870848956,0.00000078756, 3.03698313141, 12036.4607348882, 0.00000079637,1.80791330700, 17260.1546546904, 0.00000085803,5.98322631256,161000.6857376741, 0.00000056963,2.78430398043, 6286.5989683404,0.00000061148, 1.81839811024, 7084.8967811152, 0.00000069627,0.83297596966, 9437.7629348870, 0.00000056116, 4.38694880779,14143.4952424306, 0.00000062449, 3.97763880587, 8827.3902698748,0.00000051145, 0.28306864501, 5856.4776591154, 0.00000055577,3.47006009062, 6279.5527316424, 0.00000041036,5.36817351402, 8429.2412664666, 0.00000051605,1.33282746983, 1748.0164130670,0.00000051992, 0.189********, 12139.5535091068, 0.00000049000,0.48735065033, 1194.4470102246, 0.00000039200, 6.16832995016,10447.3878396044, 0.00000035566, 1.77597314691, 6812.7668150860,0.00000036770, 6.0413*******, 10213.2855462110, 0.00000036596,2.56955238628, 1059.3819301892, 0.00000033291, 0.59309499459,17789.8456197850, 0.00000035954, 1.70876111898, 2352.8661537718};private static final double E11[] = { //黄经泊松1项6283.31966747491,0.00000000000, 0.0000000000, 0.00206058863,2.67823455584, 6283.0758499914, 0.00004303430, 2.63512650414,12566.1516999828, 0.00000425264, 1.59046980729, 3.5231183490,0.00000108977, 2.96618001993, 1577.3435424478, 0.00000093478, 2.59212835365,18849.2275499742, 0.00000119261,5.79557487799, 26.2983197998, 0.00000072122, 1.138********, 529.6909650946, 0.00000067768, 1.87472304791, 398.1490034082, 0.00000067327,4.40918235168, 5507.5532386674, 0.00000059027,2.88797038460, 5223.6939198022, 0.00000055976,2.17471680261, 155.4203994342,0.00000045407, 0.39803079805, 796.2980068164, 0.00000036369,0.46624739835, 775.5226113240, 0.00000028958,2.64707383882, 7.1135470008, 0.00000019097, 1.84628332577, 5486.7778431750, 0.00000020844, 5.34138275149, 0.9803210682, 0.00000018508,4.96855124577, 213.2990954380, 0.00000016233,0.03216483047, 2544.3144198834, 0.00000017293,2.99116864949, 6275.9623029906};private static final double E12[] = { //黄经泊松2项0.00052918870, 0.00000000000, 0.0000000000, 0.00008719837,1.07209665242, 6283.0758499914, 0.00000309125, 0.86728818832,12566.1516999828, 0.00000027339, 0.05297871691, 3.5231183490,0.00000016334, 5.188********, 26.2983197998, 0.00000015752,3.68457889430, 155.4203994342, 0.00000009541, 0.75742297675,18849.2275499742, 0.00000008937, 2.0570*******, 77713.7714681205,0.00000006952, 0.82673305410, 775.5226113240, 0.00000005064,4.66284525271, 1577.3435424478};private static final double E13[] = { 0.00000289226,5.84384198723, 6283.0758499914, 0.00000034955, 0.00000000000, 0.0000000000, 0.00000016819, 5.48766912348, 12566.1516999828};private static final double E14[] = { 0.00000114084,3.14159265359, 0.0000000000, 0.00000007717,4.134********, 6283.0758499914, 0.00000000765, 3.83803776214, 12566.1516999828};private static final double E15[] = { 0.00000000878, 3.14159265359, 0.0000000000 }; private static final double E20[] = { //黄纬周期项0.00000279620, 3.198********, 84334.6615813083, 0.00000101643,5.42248619256, 5507.5532386674, 0.00000080445,3.88013204458, 5223.6939198022, 0.00000043806,3.70444689758, 2352.8661537718,0.00000031933, 4.00026369781, 1577.3435424478, 0.00000022724,3.98473831560, 1047.7473117547, 0.00000016392,3.56456119782, 5856.4776591154, 0.00000018141,4.98367470263, 6283.0758499914,0.00000014443, 3.70275614914, 9437.7629348870, 0.00000014304, 3.41117857525, 10213.2855462110};private static final double E21[] = { 0.00000009030,3.89729061890, 5507.5532386674, 0.00000006177,1.73038850355, 5223.6939198022};private static final double E30[] = { //距离周期项1.00013988799, 0.00000000000, 0.0000000000, 0.01670699626,3.09846350771, 6283.0758499914, 0.00013956023, 3.0552*******,12566.1516999828, 0.00003083720, 5.198********, 77713.7714681205,0.00001628461, 1.173********, 5753.3848848968, 0.00001575568,2.84685245825, 7860.4193924392, 0.00000924799, 5.45292234084,11506.7697697936, 0.00000542444, 4.56409149777, 3930.2096962196};private static final double E31[] = { 0.00103018608,1.10748969588, 6283.0758499914, 0.00001721238, 1.06442301418,12566.1516999828, 0.00000702215, 3.14159265359, 0.0000000000};private static final double E32[] = { 0.00004359385,5.78455133738, 6283.0758499914 };private static final double E33[] = { 0.00000144595,4.27319435148, 6283.0758499914 };//月球运动参数private static final double M10[] = {22639.5858800, 2.3555545723, 8328.6914247251, 1.5231275E-04, 2.5041111E-07,-1.1863391E-09, 4586.4383203, 8.0413790709, 7214.0628654588,-2.1850087E-04,-1.8646419E-07, 8.7760973E-10, 2369.9139357, 10.3969336431, 15542.7542901840,-6.6188121E-05, 6.3946925E-08,-3.0872935E-10, 769.0257187,4.7111091445, 16657.3828494503, 3.0462550E-04,5.0082223E-07,-2.3726782E-09,-666.4175399, -0.0431256817, 628.3019552485,-2.6638815E-06, 6.1639211E-10,-5.4439728E-11, -411.5957339, 3.2558104895, 16866.9323152810,-1.2804259E-04,-9.8998954E-09, 4.0433461E-11, 211.6555524, 5.6858244986, -1114.6285592663,-3.7081362E-04,-4.3687530E-07, 2.0639488E-09, 205.4359530, 8.0845047526, 6585.7609102104,-2.1583699E-04,-1.8708058E-07, 9.3204945E-10,191.9561973, 12.7524882154, 23871.4457149091, 8.6124629E-05, 3.1435804E-07,-1.4950684E-09, 164.7286185, 10.4400593249, 14914.4523349355,-6.3524240E-05, 6.3330532E-08,-2.5428962E-10, -147.3213842, -2.3986802540, -7700.3894694766,-1.5497663E-04,-2.4979472E-07, 1.1318993E-09, -124.9881185, 5.1984668216, 7771.3771450920,-3.3094061E-05, 3.1973462E-08,-1.5436468E-10,-109.3803637, 2.3124288905, 8956.9933799736, 1.4964887E-04, 2.5102751E-07,-1.2407788E-09, 55.1770578, 7.1411231536, -1324.1780250970, 6.1854469E-05, 7.3846820E-08,-3.4916281E-10, -45.0996092, 5.6113650618, 25195.6237400061, 2.4270161E-05, 2.4051122E-07,-1.1459056E-09, 39.5333010, -0.9002559173, -8538.2408905558, 2.8035534E-04, 2.6031101E-07,-1.2267725E-09,38.4298346, 18.4383127140, 22756.8171556428,-2.8468899E-04,-1.2251727E-07, 5.6888037E-10, 36.1238141, 7.0666637168, 24986.0742741754, 4.5693825E-04, 7.5123334E-07,-3.5590172E-09, 30.7725751, 16.0827581417, 14428.1257309177,-4.3700174E-04,-3.7292838E-07, 1.7552195E-09, -28.3971008, 7.9982533891, 7842.3648207073,-2.2116475E-04,-1.8584780E-07,8.2317000E-10,-24.3582283, 10.3538079614, 16171.0562454324,-6.8852003E-05, 6.4563317E-08,-3.6316908E-10, -18.5847068, 2.8429122493, -557.3142796331,-1.8540681E-04,-2.1843765E-07, 1.0319744E-09, 17.9544674, 5.1553411398, 8399.6791003405,-3.5757942E-05, 3.2589854E-08,-2.0880440E-10, 14.5302779, 12.7956138971, 23243.1437596606, 8.8788511E-05, 3.1374165E-07,-1.4406287E-09,14.3796974, 15.1080427876, 32200.1371396342, 2.3843738E-04, 5.6476915E-07,-2.6814075E-09, 14.2514576,-24.0810366320, -2.3011998397, 1.5231275E-04,2.5041111E-07,-1.1863391E-09, 13.8990596, 20.7938672862, 31085.5085803679,-1.3237624E-04, 1.2789385E-07,-6.1745870E-10, 13.1940636, 3.3302699264, -9443.3199839914,-5.2312637E-04,-6.8728642E-07, 3.2502879E-09,-9.6790568, -4.7542348263,-16029.0808942018,-3.0728938E-04,-5.0020584E-07, 2.3182384E-09, -9.3658635, 11.2971895604, 24080.9951807398,-3.4654346E-04,-1.9636409E-07, 9.1804319E-10, 8.6055318, 5.7289501804, -1742.9305145148,-3.6814974E-04,-4.3749170E-07, 2.1183885E-09, -8.4530982, 7.5540213938, 16100.0685698171, 1.1921869E-04, 2.8238458E-07,-1.3407038E-09,8.0501724, 10.4831850066, 14286.1503796870,-6.0860358E-05, 6.2714140E-08,-1.9984990E-10, -7.6301553, 4.6679834628, 17285.6848046987, 3.0196162E-04, 5.0143862E-07,-2.4271179E-09, -7.4474952, -0.0862513635, 1256.6039104970,-5.3277630E-06, 1.2327842E-09,-1.0887946E-10, 7.3712011, 8.1276304344, 5957.4589549619,-2.1317311E-04,-1.8769697E-07, 9.8648918E-10,7.0629900, 0.9591375719, 33.7570471374,-3.0829302E-05,-3.6967043E-08, 1.7385419E-10, -6.3831491, 9.4966777258, 7004.5133996281, 2.1416722E-04, 3.2425793E-07,-1.5355019E-09, -5.7416071, 13.6527441326, 32409.6866054649,-1.9423071E-04, 5.4047029E-08,-2.6829589E-10, 4.3740095, 18.4814383957, 22128.5152003943,-2.8202511E-04,-1.2313366E-07, 6.2332010E-10,-3.9976134, 7.9669196340, 33524.3151647312, 1.7658291E-04, 4.9092233E-07,-2.3322447E-09, -3.2096876, 13.2398458924, 14985.4400105508,-2.5159493E-04,-1.5449073E-07, 7.2324505E-10, -2.9145404, 12.7093625336, 24499.7476701576, 8.3460748E-05, 3.1497443E-07,-1.5495082E-09, 2.7318890, 16.1258838235, 13799.8237756692,-4.3433786E-04,-3.7354477E-07, 1.8096592E-09,-2.5679459, -2.4418059357, -7072.0875142282,-1.5764051E-04,-2.4917833E-07, 1.0774596E-09, -2.5211990, 7.9551277074, 8470.6667759558,-2.2382863E-04,-1.8523141E-07, 7.6873027E-10, 2.4888871, 5.6426988169, -486.3266040178,-3.7347750E-04,-4.3625891E-07, 2.0095091E-09, 2.1460741, 7.1842488353, -1952.4799803455, 6.4518350E-05, 7.3230428E-08,-2.9472308E-10,1.9777270, 23.1494218585, 39414.2000050930, 1.9936508E-05, 3.7830496E-07,-1.8037978E-09, 1.9336825, 9.4222182890, 33314.7656989005, 6.0925100E-04, 1.0016445E-06,-4.7453563E-09, 1.8707647, 20.8369929680, 30457.2066251194,-1.2971236E-04, 1.2727746E-07,-5.6301898E-10, -1.7529659, 0.4873576771, -8886.0057043583,-3.3771956E-04,-4.6884877E-07,2.2183135E-09,-1.4371624, 7.0979974718, -695.8760698485, 5.9190587E-05, 7.4463212E-08,-4.0360254E-10, -1.3725701, 1.4552986550, -209.5494658307, 4.3266809E-04,5.1072212E-07,-2.4131116E-09, 1.2618162, 7.5108957121, 16728.3705250656, 1.1655481E-04, 2.8300097E-07,-1.3951435E-09};private static final double M11[] = {1.6768000, -0.0431256817, 628.3019552485,-2.6638815E-06, 6.1639211E-10,-5.4439728E-11, 0.5164200, 11.2260974062, 6585.7609102104,-2.1583699E-04,-1.8708058E-07, 9.3204945E-10, 0.4138300, 13.5816519784, 14914.4523349355,-6.3524240E-05, 6.3330532E-08,-2.5428962E-10, 0.3711500, 5.5402729076, 7700.3894694766, 1.5497663E-04, 2.4979472E-07,-1.1318993E-09,0.2756000, 2.3124288905, 8956.9933799736, 1.4964887E-04, 2.5102751E-07,-1.2407788E-09, 0.2459863,-25.6198212459, -2.3011998397, 1.5231275E-04,2.5041111E-07,-1.1863391E-09, 0.0711800, 7.9982533891, 7842.3648207073,-2.2116475E-04,-1.8584780E-07, 8.2317000E-10, 0.0612800, 10.3538079614, 16171.0562454324,-6.8852003E-05, 6.4563317E-08,-3.6316908E-10};private static final double M12[] = { 0.0048700, -0.0431256817, 628.3019552485,-2.6638815E-06, 6.1639211E-10,-5.4439728E-11, 0.0022800,-27.1705318325, -2.3011998397, 1.5231275E-04, 2.5041111E-07,-1.1863391E-09, 0.0015000,11.2260974062, 6585.7609102104,-2.1583699E-04,-1.8708058E-07, 9.3204945E-10}; private static final double M20[] = {18461.2400600, 1.6279052448, 8433.4661576405,-6.4021295E-05,-4.9499477E-09, 2.0216731E-11, 1010.1671484, 3.9834598170, 16762.1575823656, 8.8291456E-05, 2.4546117E-07,-1.1661223E-09, 999.6936555, 0.7276493275, -104.7747329154,2.1633405E-04, 2.5536106E-07,-1.2065558E-09, 623.6524746, 8.7690283983, 7109.2881325435,-2.1668263E-06, 6.8896872E-08,-3.2894608E-10,199.4837596, 9.6692843156, 15647.5290230993,-2.8252217E-04,-1.9141414E-07, 8.9782646E-10, 166.5741153, 6.4134738261, -1219.4032921817,-1.5447958E-04,-1.8151424E-07, 8.5739300E-10, 117.2606951, 12.024*******, 23976.2204478244,-1.3020942E-04, 5.8996977E-08,-2.8851262E-10, 61.9119504, 6.3390143893, 25090.8490070907, 2.4060421E-04, 4.9587228E-07,-2.3524614E-09,33.3572027, 11.1245829706, 15437.9795572686, 1.5014592E-04, 3.1930799E-07,-1.5152852E-09, 31.7596709, 3.0832038997, 8223.9166918098, 3.6864680E-04,5.0577218E-07,-2.3928949E-09, 29.5766003, 8.8121540801, 6480.9861772950,4.9705523E-07, 6.8280480E-08,-2.7450635E-10, 15.5662654, 4.0579192538, -9548.0947169068,-3.0679233E-04,-4.3192536E-07, 2.0437321E-09,15.1215543, 14.3803934601, 32304.9118725496, 2.2103334E-05, 3.0940809E-07,-1.4748517E-09, -12.0941511, 8.7259027166, 7737.5900877920,-4.8307078E-06,6.9513264E-08,-3.8338581E-10, 8.8681426, 9.7124099974, 15019.2270678508,-2.7985829E-04,-1.9203053E-07, 9.5226618E-10, 8.0450400, 0.6687636586, 8399.7091105030,-3.3191993E-05, 3.2017096E-08,-1.5363746E-10,7.9585542, 12.0679645696, 23347.9184925760,-1.2754553E-04, 5.8380585E-08,-2.3407289E-10, 7.4345550, 6.4565995078, -1847.7052474301,-1.5181570E-04,-1.8213063E-07, 9.1183272E-10, -6.7314363, -4.0265854988,-16133.8556271171,-9.0955337E-05,-2.4484477E-07, 1.1116826E-09, 6.5795750, 16.8104074692,14323.3509980023,-2.2066770E-04,-1.1756732E-07, 5.4866364E-10,-6.4600721, 1.5847795630, 9061.7681128890,-6.6685176E-05,-4.3335556E-09,-3.4222998E-11, -6.2964773, 4.8837157343, 25300.3984729215,-1.9206388E-04,-1.4849843E-08, 6.0650192E-11, -5.6323538, -0.7707750092, 733.0766881638,-2.1899793E-04,-2.5474467E-07, 1.1521161E-09, -5.3683961, 6.8263720663, 16204.8433027325,-9.7115356E-05, 2.7023515E-08,-1.3414795E-10,-5.3112784, 3.9403341353, 17390.4595376141, 8.5627574E-05, 2.4607756E-07,-1.2205621E-09, -5.0759179, 0.6845236457, 523.5272223331,2.1367016E-04,2.5597745E-07,-1.2609955E-09, -4.8396143, -1.6710309265, -7805.1642023920, 6.1357413E-05, 5.5663398E-09,-7.4656459E-11, -4.8057401,3.5705615768, -662.0890125485, 3.0927234E-05, 3.6923410E-08,-1.7458141E-10,3.9840545, 8.6945689615, 33419.5404318159, 3.9291696E-04, 7.4628340E-07,-3.5388005E-09, 3.6744619, 19.1659620415, 22652.0424227274,-6.8354947E-05, 1.3284380E-07,-6.3767543E-10, 2.9984815, 20.0662179587, 31190.2833132833,-3.4871029E-04,-1.2746721E-07, 5.8909710E-10, 2.7986413, -2.5281611620,-16971.7070481963, 3.4437664E-04, 2.6526096E-07,-1.2469893E-09,2.4138774, 17.7106633865, 22861.5918885581,-5.0102304E-04,-3.7787833E-07, 1.7754362E-09, 2.1863132, 5.5132179088, -9757.6441827375, 1.2587576E-04, 7.8796768E-08,-3.6937954E-10, 2.1461692, 13.4801375428, 23766.6709819937, 3.0245868E-04, 5.6971910E-07,-2.7016242E-09, 1.7659832, 11.1677086523, 14809.6776020201, 1.5280981E-04, 3.1869159E-07,-1.4608454E-09,-1.6244212, 7.3137297434, 7318.8375983742,-4.3483492E-04,-4.4182525E-07, 2.0841655E-09, 1.5813036, 5.4387584720, 16552.6081165349, 5.2095955E-04, 7.5618329E-07,-3.5792340E-09, 1.5197528, 16.7359480324, 40633.6032972747, 1.7441609E-04, 5.5981921E-07,-2.6611908E-09, 1.5156341, 1.7023646816,-17876.7861416319,-4.5910508E-04,-6.8233647E-07, 3.2300712E-09,1.5102092, 5.4977296450, 8399.6847301375,-3.3094061E-05, 3.1973462E-08,-1.5436468E-10, -1.3178223, 9.6261586339, 16275.8309783478,-2.8518605E-04,-1.9079775E-07, 8.4338673E-10, -1.2642739, 11.9817132061, 24604.5224030729,-1.3287330E-04, 5.9613369E-08,-3.4295235E-10, 1.1918723, 22.4217725310, 39518.9747380084,-1.9639754E-04, 1.2294390E-07,-5.9724197E-10,1.1346110, 14.4235191419, 31676.6099173011,2.4767216E-05,3.0879170E-07,-1.4204120E-09, 1.0857810, 8.8552797618, 5852.6842220465, 3.1609367E-06, 6.7664088E-08,-2.2006663E-10, -1.0193852, 7.2392703065, 33629.0898976466,-3.9751134E-05, 2.3556127E-07,-1.1256889E-09, -0.8227141, 11.0814572888,。

相关文档
最新文档