老黄历sdk接口实现及代码示例

合集下载

用java实现简单的万年历输出的代码

用java实现简单的万年历输出的代码

package clock;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;public class Lunar {private int year;private int month;private int day;private boolean leap;final static String chineseNumber[] = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};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;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 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) {@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是当年的第几天In用java实现简单的万年历输出的代码(2009-12-14 19:08:55)转载标签:分类:计算机类itimport java.util.Scanner;public class Zuizhong{public static void main(String[] args){Scanner input=new Scanner(System.in);System.out.println("--------------------------欢迎使用万年历程序----------------------"); System.out.print("请输入年份:");int year=input.nextInt();System.out.print("\n请输入月份:");int month=input.nextInt();//打印换行符System.out.println();//计算1900年1月1日到指定年份前一年的天数int totalDays=0;//判断是否是1900后的年份if(year>=1900){for(int i=1900;i<year;i++){//判断是否闰年,闰年加366天,否则加365天if((i%4==0 && i%100!=0)||(i%400==0))totalDays+=366;else totalDays+=365;}//计算指定年份1月到指定月份1号之间的天数int daysOfMonth=0;int days;for(int i=1;i<month;i++){switch(i){case 2:if((year%4==0 && year%100!=0)|| year%400==0) days=29;else days=28;break;case 4:case 6:case 9:case 11:days=30;break;default:days=31;}daysOfMonth+=days;}//获得指定年月的天数switch(month){case 2:if((year%4==0 && year%100!=0)|| year%400==0) days=29;else days=28;break;case 4:case 6:case 9:case 11:days=30;break;default:days=31;}//1900.1.1到指定年月1号之间的总天数totalDays+=daysOfMonth;//计算指定年月1号的星期数int firstDay=(totalDays)%7+1;//上一行算出的星期数是1到7,因此要转换成0-6,即星期日=0if(firstDay==7)firstDay=0;//显示月历System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");//打印1号之前的空格for(int i=0;i<firstDay;i++)System.out.print("\t");//打印月历for(int i=1;i<=days;i++){System.out.print(i+"\t");//如果是星期六,换行if((i-1)%7+firstDay==6)System.out.println();}}else if(year>0&&year<1900){for(int i=1899;i>year;i--){//判断是否闰年,闰年加366天,否则加365天if((i%4==0 && i%100!=0)||(i%400==0))totalDays+=366;else totalDays+=365;}//计算指定年份12月到指定月份31号之后的天数int daysOfMonth=0;int days;for(int i=12;i>=month;i--){switch(i){case 2:if((year%4==0 && year%100!=0)|| year%400==0) days=29;else days=28;break;case 4:case 6:case 9:case 11:days=30;break;default:days=31;}daysOfMonth+=days;}//获得指定年月的天数switch(month){case 2:if((year%4==0 && year%100!=0)|| year%400==0) days=29;else days=28;break;case 4:case 6:case 9:case 11:days=30;break;default:days=31;}//1900.1.1到指定年月1号之间的总天数totalDays+=daysOfMonth;//计算指定年月1号的星期数int firstDay=8-(totalDays)%7;//上一行算出的星期数是1到7,因此要转换成0-6,即星期日=0if(firstDay==7)firstDay=0;if(firstDay==8)firstDay=1;//显示月历System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");//打印1号之前的空格for(int i=0;i<firstDay;i++)System.out.print("\t");//打印月历for(int i=1;i<=days;i++){System.out.print(i+"\t");//如果是星期六,换行if((i-1)%7+firstDay==6)System.out.println();}}System.out.println("\n程序结束");}}(完)在myeclipse运行效果图:--------------------------欢迎使用万年历程序---------------------- 请输入年份:2009请输入月份:12星期日星期一星期二星期三星期四星期五星期六1 2 3 4 56 7 8 9 10 11 1213 14 15 16 17 18 1920 21 22 23 24 25 2627 28 29 30 31程序结束。

JAVA课程设计 万年历 源代码

JAVA课程设计 万年历 源代码

测试用例设计:根据 需求文档和功能描述, 设计出能够覆盖所有 功能的测试用例
测试工具:使用JUnit 等测试框架进行单元 测试,使用Selenium 等工具进行UI测试
测试结果分析:根 据测试结果,分析 代码存在的问题, 并进行修改和优化
集成测试:验证各个模块之间的接口是否正确,数据传输是否正常 性能测试:测试系统的响应时间、吞吐量、资源利用率等性能指标
提醒功能:用户可以设置提醒功能,在节日或假期到来之前,系统会自动提醒用户。
删除事件:用户可以删除不 再需要的事件
编辑事件:用户可以对已添加 的事件进行编辑,如修改事件 名称、时间等
添加事件:用户可以在万年历 中添加新的事件,如生日、纪 念日等
查询事件:用户可以查询特定 日期或时间段内的事件,如查
界面显示:万年历界面将显示年、 月、日、星期等信息,用户可以通 过点击相应的按钮来切换日期。
添加标题
添加标题
添加标题
添加标题
系统响应:当用户输入日期后,系统 将根据输入的日期显示相应的万年历 信息,包括年、月、日、星期等信息。
用户操作:用户可以通过点击相应 的按钮来切换日期,系统将根据用 户的操作显示相应的万年历信息。
添加标题
界面设计:简洁明了,易于阅读
添加标题
添加标题
交互性:用户可以选择查看不同日 期的日历信息
功能描述:在万年历中,用户可以选择标注节日和假期,以便于查看和提醒。
节日标注:用户可以在万年历中设置自己喜欢的节日,如春节、中秋节等,系统会自动 标注这些节日。
假期标注:用户可以在万年历中设置自己的假期,如年假、病假等,系统会自动标注这 些假期。
,a click to unlimited possibilities

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) { }}。

SDK 代码

SDK 代码

在header区域显示内容第一步header 店铺全局的头部配置布局信息配置片区显示内容体验<div class="layout grid-m"> 定义通栏样式<div class=" J_TRegion"> 定义片区<div class="box J_TBox"> 内容<?phpecho "你好";echo "<br />"; 换行echo "哈哈";?></div></div></div>第二步一:准备图片素材二:平台建模块三:编写PHP文件即*新建一个模块modules\dz\dz.pnp代码如下<div class="box J_TBOX"><div class="dz"><img src="assets/images/dz/dz.jpg"/></div></div>四:在header中显示cs02\header.pnp插入篮色代码,代码如下<div class="layout grid-m"><div class="j_tregion"><div class="box j_tbox"><?phpecho include_local_module("dz",dz);?></div>五:配置参数cs02\modules\dz\module插入篮色代码<?xml version="1.0" encoding="GBK" standalone="yes"?><module xsi:noNamespaceSchemaLocation="../../module.xsd" xmlns:xsi="/2001/XMLSchema-instance"><id>dz</id><name>店招图</name><file>dz.php</file><thumbnail>assets/images/dz.png</thumbnail><description>店招</description><requiredCache>true</requiredCache><parameters><param name="dztp_01" label="店招图片" description="输入店招图片地址(950px*157px;)" ptype="text" formType="text">assets/images/dz/dz.jpg</param></parameters></module>六:完成PHP语句,实现交互式操作,即返回modules\dz\dz.pnp插入篮色部分<div class="box J_TBox" <?php echo $_MODULE_TOOLBAR ?>><div class="dz"><?phpif($_MODULE[dztp_01]){echo '<img src="'.$_MODULE[dztp_01].'"/>'}else{echo '<img src="assets/images/dz/dz.jpg"/>';}?></div></div>完成上述步骤在平台http://192.168.0.100:8080/cs02/index.htm后加?debug测试图片上出现编辑对话框OK。

梦哈——日历控件.html

梦哈——日历控件.html
style="background-color: #DCDCDC"></td><td>控件的暗文字颜色</td>
<td><input value="#F5F5FA" onchange="WebCalendar.dayBgColor = this.value; this.style.backgroundColor = this.value"
代码:<span class=code>&lt;input name="txt" onfocus="calendar()"&gt;&lt;input type=button
value=calendar onclick="calendar(document.form1.txt)"&gt;</span></fieldset>
Web Calendar ver 2.0 Author: walkingpoison(水晶龙) mail: wayx@ /Expert/TopicView1.asp?id=1264734
<b>Web Calendar 的第二种调用方法:</b>
<input name="txt" onfocus="calendar()"><input type=button value=calendar onclick="calendar(document.form1.txt)"><br><br>
<td><input value="#FFFFFF" onchange="WebCalendar.lightColor = this.value; this.style.backgroundColor = this.value"

基于C#的节假日日历接口调用代码实例

基于C#的节假日日历接口调用代码实例

基于C#的节假日日历接口调用代码实例代码描述:基于C#的节假日日历接口调用代码实例代码平台:聚合数据using System;using System.Collections.Generic;using System.Linq;using System.Text;using ;using System.IO;using ;using System.Diagnostics;using System.Web;//----------------------------------// 万年历调用示例代码-聚合数据// 在线接口文档:/docs/177// 代码中JsonObject类下载地址:/download/gcm32060 21155665/7458439//----------------------------------namespace ConsoleAPI{class Program{static void Main(string[] args){string appkey = "*******************"; //配置您申请的appkey//1.获取当天的详细信息string url1 = "/calendar/day";var parameters1 = new Dictionary<string, string>();parameters1.Add("key", appkey);//你申请的keyparameters1.Add("date", ""); //指定日期,格式为YYYY-MM-DD,如月份和日期小于10,则取个位,如:2012-1-1string result1 = sendPost(url1, parameters1, "get");JsonObject newObj1 = new JsonObject(result1);String errorCode1 = newObj1["error_code"].Value;if(errorCode1 == "0"){Debug.WriteLine("成功");Debug.WriteLine(newObj1);}else{//Debug.WriteLine("失败");Debug.WriteLine(newObj1["error_code"].Value+":"+newObj1 ["reason"].Value);}//2.获取当月近期假期string url2 = "/calendar/month";var parameters2 = new Dictionary<string, string>();parameters2.Add("key", appkey);//你申请的keyparameters2.Add("year-month", ""); //指定月份,格式为YYYY-MM,如月份和日期小于10,则取个位,如:2012-1string result2 = sendPost(url2, parameters2, "get");JsonObject newObj2 = new JsonObject(result2);String errorCode2 = newObj2["error_code"].Value;if(errorCode2 == "0"){Debug.WriteLine("成功");Debug.WriteLine(newObj2);}else{//Debug.WriteLine("失败");Debug.WriteLine(newObj2["error_code"].Value+":"+newObj2 ["reason"].Value);}//3.获取当年的假期列表string url3 = "/calendar/year";var parameters3 = new Dictionary<string, string>();parameters3.Add("key", appkey);//你申请的keyparameters3.Add("year", ""); //指定年份,格式为YYYY,如:2015string result3 = sendPost(url3, parameters3, "get");JsonObject newObj3 = new JsonObject(result3);String errorCode3 = newObj3["error_code"].Value;if(errorCode3 == "0"){Debug.WriteLine("成功");Debug.WriteLine(newObj3);}else{//Debug.WriteLine("失败");Debug.WriteLine(newObj3["error_code"].Value+":"+newObj3 ["reason"].Value);}}/// <summary>/// Http (GET/POST)/// </summary>/// <param name="url">请求URL</param>/// <param name="parameters">请求参数</param>/// <param name="method">请求方法</param>/// <returns>响应内容</returns>static string sendPost(string url, IDictionary<string, string> p arameters, string method){if(method.ToLower() == "post"){HttpWebRequest req = null;HttpWebResponse rsp = null;System.IO.Stream reqStream = null;try{req = (HttpWebRequest)WebRequest.Create(url);req.Method = method;req.KeepAlive = false;req.ProtocolVersion = HttpVersion.Version10;req.Timeout = 5000;req.ContentType = "application/x-www-form-urlencode d;charset=utf-8";byte[] postData = Encoding.UTF8.GetBytes(BuildQuery (parameters, "utf8"));reqStream = req.GetRequestStream();reqStream.Write(postData, 0, postData.Length);rsp = (HttpWebResponse)req.GetResponse();Encoding encoding = Encoding.GetEncoding(rsp.Charac terSet);return GetResponseAsString(rsp, encoding);}catch(Exception ex){return ex.Message;}finally{if(reqStream != null) reqStream.Close();if(rsp != null) rsp.Close();}}else{//创建请求HttpWebRequest request = (HttpWebRequest)WebRequest.Cre ate(url + "?"+ BuildQuery(parameters, "utf8"));//GET请求request.Method = "GET";request.ReadWriteTimeout = 5000;request.ContentType = "text/html;charset=UTF-8";HttpWebResponse response = (HttpWebResponse)request.Get Response();Stream myResponseStream = response.GetResponseStream();StreamReader myStreamReader = new StreamReader(myRespons eStream, Encoding.GetEncoding("utf-8"));//返回内容string retString = myStreamReader.ReadToEnd();return retString;}}/// <summary>/// 组装普通文本请求参数。

基于JAVA的每日宜忌查询API调用代码实例

基于JAVA的每日宜忌查询API调用代码实例
params.put("key",APPKEY);//应用 APPKEY(应用详细页查询) params.put("date","");//日期,格式 2014-09-09
try { result =net(url, params, "GET"); JSONObject object = JSONObject.fromObject(result); if(object.getInt("error_code")==0){ System.out.println(object.get("result")); }else{ System.out.println(object.get("error_code")+":"+object.
strUrl = strUrl+"?"+urlencode(params); } URL url = new URL(strUrl); conn = (HttpURLConnection) url.openConnection(); if(method==null || method.equals("GET")){
get("reason")); }
} catch (Exception e) { e.printStackTrace();
} }
//2.时辰 public static void getRequest2(){
String result =null; String url ="/laohuangli/h";//请求接口地址 Map params = new HashMap();//请求参数

JAVA《万年历系统》课程设计报告附源码

JAVA《万年历系统》课程设计报告附源码

2013-2014学年第二学期《面向对象程序设计》课程设计报告题目:万年历系统专业:计算机科学与技术班级:姓名:学号:指导教师:成绩:计算机与信息工程系2014年6月6日目录1 设计内容及要求 (1)1.1设计内容 (1)1.2设计任务及具体要求 (1)2 概要设计 (2)2.1程序设计思路 (2)2.2 总体程序框图 (3)3 设计过程或程序代码 (4)3.1各个模块的程序流程图及运行界面 (4)3.2对关键代码加以分析说明 (7)4 设计结果与分析 (13)4.1程序调试的结果 (13)4.2程序设计分析 (13)5 小结 (14)致谢 (15)参考文献 (16)源程序 (17)1 设计内容及要求1.1设计内容万年历,实际上就是记录一定时间范围内(比如100年或更多)的具体阳历或阴历的日期的年历,方便有需要的人查询使用。

在我设计的万年历中主要有:(1)使用图形用户界面来查询用用户所需的日期信息,符合日常软件使用规范。

(2)按月份查询,实现了显示查询1901~2100年某月所有日期的阴阳历对照。

(3)并且添加了重大节日与星座等信息,界面采用日常的星期与月份结合的格式,方便查看与使用。

(4)编写万年历的课程设计,是为了使同学们更加了解高级程序设计语言的结构,掌握基本的程序设计过程和技巧,掌握基本的分析问题和利用计算机求解问题的能力,具备初步的高级语言程序设计能力。

为后续各门计算机课程的学习和毕业设计打下坚实基础。

1.2设计任务及具体要求利用JAVA语言编写的万年历系统采用了多种JAVA语句来实现多种功能。

用户可以通过本程序的applet运行界面来查找一整年某月的农历和阳历,可以查找用户所想了解的某一天具体为星期几,并且可以看到一些重大节日的具体时间。

要求:满足设计万年历系统的目的,即当用户查询年份与月份时,系统就要将这一年的某一月份的阴历与阳历全部显示出来,并且附带这一月份的重大节日。

当用户随意改动年份或月份时系统自动显示与星期对应的日期。

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

老黄历sdk接口实现及代码示例
老黄历sdk提供老黄历查询,黄历每日吉凶宜忌查询。

接口名称:老黄历sdk
接口平台:聚合数据
接口地址:/laohuangli/d
支持格式:JSON/XML
请求方式:HTTP GET/POST
请求示例:/laohuangli/d?date=2014-09-11&key=您申请的KEY 老黄历日历sdk接口JSON返回示例:
{
"reason": "successed",
"result": {
"id": "1657",
"yangli": "2014-09-11",
"yinli": "甲午(马)年八月十八",
"wuxing": "井泉水建执位",
"chongsha": "冲兔(己卯)煞东",
"baiji": "乙不栽植千株不长酉不宴客醉坐颠狂",
"jishen": "官日六仪益後月德合除神玉堂鸣犬",
"yi": "祭祀出行扫舍馀事勿取",
"xiongshen": "月建小时土府月刑厌对招摇五离",
"ji": "诸事不宜"
},
"error_code": 0
}
老黄历时辰sdk接口JSON返回示例:
{
"reason": "successed",
"result": [
{
"yangli": "2014-09-11",
"hours": "1-3",
"des": " 修造安葬求财见贵嫁娶进人口移徙",
"yi": "赴任出行",
"ji": "冲猴煞北时冲甲申地兵三合长生司命"
},
{
"yangli": "2014-09-11",
"hours": "3-5",
"des": " 祈福求嗣订婚嫁娶出行求财开市交易安床作灶祭祀",
"yi": "修造动土",
"ji": "冲猪煞东时冲丁亥路空日禄明堂"
}, {
"yangli": "2014-09-11",
"hours": "5-7",
"des": " 赴任修造移徙出行词讼祈福求嗣",
"yi": "求财见贵祭祀酬神",
"ji": "冲狗煞南时冲丙戍日破"
},
{
"yangli": "2014-09-11",
"hours": "7-9",
"des": " 赴任出行修造",
"yi": "冲马煞南时冲壬午天牢六戊天官福星",
"ji": "求财见贵祭祀酬神"
},
{
"yangli": "2014-09-11",
"hours": "9-11",
"des": " 赴任修造移徙出行词讼祈福求嗣",
"yi": "冲羊煞东时冲癸未日刑元武太阴国印",
"ji": "祭祀祈福合脊嫁娶安葬"
},
{
"yangli": "2014-09-11",
"hours": "11-13",
"des": " 冲鼠煞北时冲戊子三合大进帝旺贪狼",
"yi": "祈福求嗣订婚嫁娶出行求财开市交易安床赴任", "ji": "-"
},
{
"yangli": "2014-09-11",
"hours": "13-15",
"des": " 冲牛煞西时冲己丑日刑朱雀右弼",
"yi": "见贵求财嫁娶进人口移徙安葬",
"ji": "赴任出行朱雀须用凤凰符制否则诸事不宜"
},
{
"yangli": "2014-09-11",
"hours": "15-17",
"des": " 冲虎煞南时冲庚寅天兵喜神金匮左辅",
"yi": "祈福求嗣订婚嫁娶出行求财开市交易安床赴任见贵", "ji": "上梁盖屋入殓"
},
{
"yangli": "2014-09-11",
"hours": "17-19",
"des": " 冲兔煞东时冲辛卯狗食天赦贵人宝光",
"yi": "修造入宅安葬出行求财见贵订婚嫁娶",
"ji": "祭祀祈福斋醮酬神"
},
{
"yangli": "2014-09-11",
"hours": "19-21",
"des": " 冲龙煞北时冲壬辰日建六戊白虎武曲", "yi": "祭祀斋醮订婚嫁娶出行安葬",
"ji": "造船乘船祈福求嗣白虎须用麒麟符制否则诸事不宜"
},
{
"yangli": "2014-09-11",
"hours": "21-23",
"des": " 冲蛇煞西时冲癸已大退玉堂贵人少微",
"yi": "盖屋移徙安床入宅开市开仓祭祀祈福酬神出行求财见贵订婚嫁娶",
"ji": "开光修造安葬"
},
{
"yangli": "2014-09-11",
"hours": "23-1",
"des": " 祭祀祈福斋醮开光赴任出行",
"yi": "求财见贵订婚嫁娶入宅开市安葬修造盖屋移徙作灶安床",
"ji": "冲鸡煞西时冲乙酉勾陈天地"
}
],
"error_code": 0
}。

相关文档
最新文档