带农历的日期代码

合集下载

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

C 万年历及公历农历转换源代码1

C  万年历及公历农历转换源代码1

scanf("%d.%d.%d",&gyear,&gmonth,&gday); if(gyear%4==0 && gyear%100!=0 || gyear%400==0) months[2]=29; else months[2]=28; /*以下是计算在该公历年的第几天*/
whatday=gPastday[gmonth]+gday; if((gyear%4==0 && gyear%100!=0 || gyear%400==0) && (gmonth>2)) whatday++; /*上如果是闰年和月份大于二则在该公历年的第几天数+1*/ /*计算该年春节在公历年的第几天*/
clrscr();
}
}
getch();
}
/*公历每月前面的天数*/ const int gPastday[13]={0,0,31,59,90,120,151,181,212,243,273,304,334};
months[13]={0,31,0,31,30,31,30,31,31,30,31,30,31};
{case 1:printf("
* 1 * "); break;
case 3:printf("
* 3 * "); break;
case 5:printf("
* 5 * "); break;
case 7:printf("
* 7 * "); break;
case 9:printf("
* 9 * ");break;
{

农历时间日期代码

农历时间日期代码

农历时间日期<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>单行带农历的日期时间代码</title></head><body><SCRIPT language=JavaScript><!--function CalConv(){FIRSTYEAR = 1998;LASTYEAR = 2031;today = new Date();SolarYear = today.getFullYear();SolarMonth = today.getMonth() + 1;SolarDate = today.getDate();Weekday = today.getDay();LunarCal = [new tagLunarCal( 27, 5, 3, 43, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1 ),new tagLunarCal( 46, 0, 4, 48, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 ), /* 88 */ new tagLunarCal( 35, 0, 5, 53, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 ), /* 89 */ new tagLunarCal( 23, 4, 0, 59, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),new tagLunarCal( 42, 0, 1, 4, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),new tagLunarCal( 31, 0, 2, 9, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0 ),new tagLunarCal( 21, 2, 3, 14, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1 ), /* 93 */ new tagLunarCal( 39, 0, 5, 20, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 ),new tagLunarCal( 28, 7, 6, 25, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1 ),new tagLunarCal( 48, 0, 0, 30, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1 ),new tagLunarCal( 37, 0, 1, 35, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 ), /* 97 */ new tagLunarCal( 25, 5, 3, 41, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ),new tagLunarCal( 44, 0, 4, 46, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ),new tagLunarCal( 33, 0, 5, 51, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ),new tagLunarCal( 22, 4, 6, 56, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ), /* 101 */ new tagLunarCal( 40, 0, 1, 2, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ),new tagLunarCal( 30, 9, 2, 7, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 ),new tagLunarCal( 49, 0, 3, 12, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1 ),new tagLunarCal( 38, 0, 4, 17, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0 ), /* 105 */ new tagLunarCal( 27, 6, 6, 23, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1 ),new tagLunarCal( 46, 0, 0, 28, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0 ),new tagLunarCal( 35, 0, 1, 33, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 ),new tagLunarCal( 24, 4, 2, 38, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ), /* 109 */new tagLunarCal( 42, 0, 4, 44, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ),new tagLunarCal( 31, 0, 5, 49, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0 ),new tagLunarCal( 21, 2, 6, 54, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 ),new tagLunarCal( 40, 0, 0, 59, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 ), /* 113 */new tagLunarCal( 28, 6, 2, 5, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 ),new tagLunarCal( 47, 0, 3, 10, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1 ),new tagLunarCal( 36, 0, 4, 15, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 ),new tagLunarCal( 25, 5, 5, 20, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 ), /* 117 */new tagLunarCal( 43, 0, 0, 26, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 ),new tagLunarCal( 32, 0, 1, 31, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0 ),new tagLunarCal( 22, 3, 2, 36, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0 ) ];/* 民國年每月之日數all by */SolarCal = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];/* 民國年每月之累積日數, 平年與閏年*/SolarDays = [ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 396, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 397 ];if ( SolarYear <= FIRSTYEAR || SolarYear > LASTYEAR ) return 1;sm = SolarMonth - 1;if ( sm < 0 || sm > 11 ) return 2;leap = GetLeap( SolarYear );if ( sm == 1 )d = leap + 28;elsed = SolarCal[sm];if ( SolarDate < 1 || SolarDate > d ) return 3;y = SolarYear - FIRSTYEAR;acc = SolarDays[ leap*14 + sm ] + SolarDate;kc = acc + LunarCal[y].BaseKanChih;Kan = kc % 10;Chih = kc % 12;Age = kc % 60;if ( Age < 22 )Age = 22 - Age;elseAge = 82 - Age;if ( acc <= LunarCal[y].BaseDays ) {y--;LunarYear = SolarYear - 1;leap = GetLeap( LunarYear );sm += 12;acc = SolarDays[leap*14 + sm] + SolarDate;}elseLunarYear = SolarYear;l1 = LunarCal[y].BaseDays;for ( i=0; i<13; i++ ) {l2 = l1 + LunarCal[y].MonthDays[i] + 29;if ( acc <= l2 ) break;l1 = l2;}LunarMonth = i + 1;LunarDate = acc - l1;im = LunarCal[y].Intercalation;if ( im != 0 && LunarMonth > im ) {LunarMonth--;if ( LunarMonth == im ) LunarMonth = -im;}if ( LunarMonth > 12 ) LunarMonth -= 12;today=new Date();function initArray(){this.length=initArray.arguments.lengthfor(var i=0;i<this.length;i++)this[i+1]=initArray.arguments[i] }var d=new initArray("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); document.write("", today.getYear(),"年",today.getMonth()+1,"月",today.getDate(),"日&nbsp;",d[today.getDay()+1],"");months = ["一","二","三","四","五","六","七","八","九","十","十一","十二"];days = ["初一","初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"];document.write( "&nbsp;农历"+months[LunarMonth-1]+"月" + days[LunarDate-1] + "");return 0;}/* 求此民國年是否為閏年, 返回0 為平年, 1 為閏年*/function GetLeap( year ){if ( year % 400 == 0 )return 1;else if ( year % 100 == 0 )return 0;else if ( year % 4 == 0 )return 1;elsereturn 0;}function tagLunarCal( d, i, w, k, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13) { this.BaseDays = d; /* 到民國1 月1 日到農曆正月初一的累積日數*/this.Intercalation = i; /* 閏月月份. 0==此年沒有閏月*/this.BaseWeekday = w; /* 此年民國1 月1 日為星期幾再減1 */this.BaseKanChih = k; /* 此年民國1 月1 日之干支序號減1 */this.MonthDays = [ m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13 ]; /* 此農曆年每月之大小, 0==小月(29日), 1==大月(30日) */}//--></SCRIPT><a target=_blank href=><FONT color=#2b68a7><SCRIPT>CalConv();</SCRIPT></FONT></a></body></html>本代码由<a href=>网页特效网</a>提供QQ菜单似的下拉门<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><title>下拉滚动门</title><style type="text/css">body{margin:10px;padding:10px;}body,td,div,span,li{font-size:12px;}.title01,.title02{color:#fff;font-weight:bold;}#DoorP{border:12px solid #eee; width:150px;height:300px;padding:4px; background:#fff;}.title01{width:100%;height:25px; background:#00ccff; cursor:pointer;}.title02{width:100%;height:25px; background:#99cc00; cursor:pointer;}.content{background:#eee;border-bottom:2px solid #fff; overflow:hidden;color:#666;padding-left:4px;padding-right:4px;line-height:18px;}</style><!--棕:#eee;蓝:#00ccff;绿:#99cc00;--></head><body><div id="DoorP"><table><tr><td>第一层信息</td></tr></table><div class="content">十三妖<br/>十三妖<br/>十三妖<br/></div><table><tr><td>第二层信息</td></tr></table><div class="content"> ThirdteenDevil</div><table><tr><td>第三层信息</td></tr></table><div class="content">devil13th</div></div><script type="text/javascript">var open = 2;// 设置初始打开的层序号var openState = new Array();var closeState = new Array();var dH = 220;function $(id){if(document.getElementById(id)) {return document.getElementById(id); }else{alert("没有找到!");}}function $tag(id,tagName){return $(id).getElementsByTagName(tagName)}function closeMe(Cid,Oid){var h = parseInt(Ds[Cid].style.height);//alert(h);if(h > 0){h = h - Math.ceil(h/3);Ds[Cid].style.height = h+"px";}else{openMe(Oid);clearTimeout(closeState[Cid]);return false;}closeState[Cid] = setTimeout("closeMe("+Cid+","+Oid+")"); }function openMe(Oid){var h = parseInt(Ds[Oid].style.height);//alert(h);if(h < dH){h = h + Math.ceil((dH-h)/3);Ds[Oid].style.height = h+"px";}else{clearTimeout(openState[Oid]);return false;}openState[Oid] = setTimeout("openMe("+Oid+")");}var Ds = $tag("DoorP","div");var Ts = $tag("DoorP","table");if(Ds.length != Ts.length){alert("标题和内容数目不相同!");}for(var i = 0 ; i < Ds.length ; i++){if(i==open){Ds[i].style.height = dH+"px";Ts[i].className="title01";}else{Ds[i].style.height = "0px";Ts[i].className="title02";}Ts[i].value = i;Ts[i].onclick = function(){if(open==this.value){return false;}Ts[open].className="title02";Ts[this.value].className="title01";for(var i = 0 ; i < openState.length ; i++){clearTimeout(openState[i]);clearTimeout(closeState[i]);}closeMe(open,this.value);//openMe(this.value);open = this.value;}}//直接打开层函数function showDiv(id){Ds[id].style.height=dH+"px";Ds[open].style.height="0px";open = id;}//渐渐打开层函数</script></body></html>本代码由<a href=>网页特效网</a>提供文字的折叠与展开<div align="center"><table border="0" width="300" cellpadding="0" style="border-collapse: collapse" id="table1" bgcolor="#F3F3F3" cellspacing="10"><tr><td valign="top" style="line-height: 150%"><div class="block" id="smallContent" style="display:block"><span style="font-size: 9pt"> <b>专辑介绍:</b>青春光影是由中国80后影像精英共同组建的新媒体影视摄制机构。

js实现的带有农历的日历

js实现的带有农历的日历

js实现的带有农历的日历<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""><html xmlns=""><head></head><body><script>var CalendarData=new Array(20);var madd=new Array(12);var TheDate=new Date();var tgString="甲乙丙丁戊己庚辛壬癸";var dzString="子丑寅卯辰巳午未申酉戌亥";var numString="一二三四五六七八九十";var monString="正二三四五六七八九十冬腊";var weekString="日一二三四五六";var sx="鼠牛虎兔龙蛇马羊猴鸡狗猪";var cYear;var cMonth;var cDay;var cHour;var cDateString;var DateString;var Browser=navigator.appName;var bsDate;var bsDate2;var bsWeek;var bsYear;var bsYear2;function init(){CalendarData[0]=0x41A95; CalendarData[1]=0xD4A; CalendarData[2]=0xDA5; CalendarData[3]=0x20B55; CalendarData[4]=0x56A; CalendarData[5]=0x7155B; CalendarData[6]=0x25D; CalendarData[7]=0x92D; CalendarData[8]=0x5192B; CalendarData[9]=0xA95; CalendarData[10]=0xB4A; CalendarData[11]=0x416AA; CalendarData[12]=0xAD5; CalendarData[13]=0x90AB5; CalendarData[14]=0x4BA; CalendarData[15]=0xA5B; CalendarData[16]=0x60A57; CalendarData[17]=0x52B; CalendarData[18]=0xA93; CalendarData[19]=0x40E95; madd[0]=0;madd[1]=31;madd[2]=59;madd[3]=90;madd[4]=120;madd[5]=151;madd[6]=181;madd[7]=212;madd[8]=243;madd[9]=273;madd[10]=304;madd[11]=334;}function GetBit(m,n){return (m>>n)&1;}function e2c(){var total,m,n,k;var isEnd=false;var tmp=TheDate.getYear();if (tmp<1900) tmp+=1900;total=(tmp-2001)*365+Math.floor((tmp-2001)/4)+madd[TheDate.getMonth()]+TheDate.getDate()-23;if (TheDate.getYear()%4==0&&TheDate.getMonth()>1) total++;for(m=0;;m++){k=(CalendarData[m]<0xfff)?11:12;for(n=k;n>=0;n--){if(total<=29+GetBit(CalendarData[m],n)){isEnd=true;break;}total=total-29-GetBit(CalendarData[m],n);}if(isEnd)break;}cYear=2001 + m;cMonth=k-n+1;cDay=total;if(k==12){if(cMonth==Math.floor(CalendarData[m]/0x10000)+1) cMonth=1-cMonth;if(cMonth>Math.floor(CalendarData[m]/0x10000)+1) cMonth--;}cHour=Math.floor((TheDate.getHours()+3)/2);}function GetcDateString(){ var tmp="";var tmp2="";tmp+=tgString.charAt((cYear-4)%10); //年干tmp+=dzString.charAt((cYear-4)%12); //年支tmp+="年(";tmp+=sx.charAt((cYear-4)%12);tmp+=") ";bsYear=tmp;if(cMonth<1){tmp2+="闰";tmp2+=monString.charAt(-cMonth-1);}elsetmp2+=monString.charAt(cMonth-1);tmp2+="月";tmp2+=(cDay<11)?"初":((cDay<20)?"十":((cDay<30)?"廿":"卅"));if(cDay%10!=0||cDay==10)tmp2+=numString.charAt((cDay-1)%10);bsYear2=tmp2;cDateString=tmp;return tmp;}function GetDateString(){var tmp="";var t1=TheDate.getYear();if (t1<1900)t1+=1900;tmp+=t1+"年"+(TheDate.getMonth()+1)+"月" ;bsDate=tmp;bsDate2=TheDate.getDate();bsWeek= "星期"+weekString.charAt(TheDate.getDay());DateString=tmp;alert(tmp)return tmp;}init();e2c();GetDateString();GetcDateString();function CAL(){document.write("<table border='1'align='center' cellspacing='3' width='90' bordercolor='#9FC6F1' bgcolor='#FFFFFF' height='110' cellpadding='2'");document.write("<tr><td align='center' style='font-size: 9pt; font-family: 宋体'><b><font color=#5478B3>"+bsDate+"</font><br><font face='Arial' size='6' color=#FF8040>"+bsDate2+"</font><br><font color=#5478B3><span style='FONT-SIZE: 10.5pt'>");document.write(bsWeek+"</span><br>"+"<br></b><fon t color=#9B4E00>");document.write(bsYear+"<br>"+bsYear2+"</td></tr></ta ble>");}CAL();</script></body></html>。

python生日提醒_Python实现农历生日提醒功能

python生日提醒_Python实现农历生日提醒功能

python生日提醒_Python实现农历生日提醒功能农历生日提醒是一种非常实用的功能,能够帮助我们记住家人和朋友的农历生日,并在特定日期提醒我们发送祝福或者准备礼物。

在这篇文章中,我将使用Python来实现农历生日提醒功能。

``````安装完成后,我们可以开始编写代码了。

首先,我们需要引入需要的库:```pythonimport tkinter as tkfrom lunarcalendar import Converter, Solar```接下来,我们需要定义一个函数来获取当前的农历日期:```pythondef get_lunar_date(:solar = Solar(today.year, today.month, today.day)lunar = Converter(.solar_to_lunar(solar)return lunar```接下来,我们需要定义一个函数来检查是否有农历生日需要提醒,并在有生日需要提醒时弹出一个消息框:```pythondef check_birthday(:lunar_date = get_lunar_datelunar_month = lunar_date.monthlunar_day = lunar_date.dayif (lunar_month, lunar_day) in birthday_dict:name = birthday_dict[(lunar_month, lunar_day)]message = f"今天是{name}的农历生日!"tk.messagebox.showinfo("生日提醒", message)```在该函数中,我们首先获取当前的农历日期。

然后,我们使用获取的农历日期作为键来查找生日字典birthday_dict中是否有对应的生日。

接下来,我们需要定义一个函数来添加生日信息到生日字典:```pythondef add_birthday(:name = name_entry.getdate = date_entry.getlunar_date = Converter(.solar_to_lunar(Solar(lunar_date.year, lunar_date.month, lunar_date.day))birthday_dict[(lunar_date.month, lunar_date.day)] = namename_entry.delete(0, tk.END)date_entry.delete(0, tk.END)```在该函数中,我们首先从输入框中获取生日人的姓名和农历日期。

C语言万年历代码

C语言万年历代码
printf(" ");
}
for(a=1;a<=30;a++)
{
c++;
if(c%7-1==0&&c!=1)
printf("\n");
{
c++;
printf(" ");
}
for(a=1;a<=_m;a++)
{
c++;
if(c%7-1==0&&c!=1)
} Βιβλιοθήκη else { c=0;
printf("┈━═☆ ┈━═☆ ┈━═☆ \n");
printf(" ◇ %d月 ◇ \n",yue);
printf("============================\n");
{
c=0;
printf("\n");
printf("┈━═☆ ┈━═☆ ┈━═☆ \n");
printf(" ◇ %d月 ◇ \n",yue);
printf("============================\n");
printf(" 日 一 二 三 四 五 六\n");
if(yue==4||yue==6||yue==9||yue==11||yue==2)
{
if(yue==2)
{
c=0;
printf("┈━═☆ ┈━═☆ ┈━═☆ \n");

日历实现vb代码

日历实现vb代码

日历实现vb代码Dim tian, di As StringDim cyear, cmonth, cday As Integer Dim year1, month1, day1 As Integer Dim n, k, i, j As IntegerDim total As LongDim date1, date2 As DateDim IsendAs BooleanDim st As StringDim data(100) As StringDim yueDim temp As IntegerPrivate Sub Combo2_click()year1 = Val(Combo2.Text)month1 = Val(Combo1.Text)day1 = 1Isend = Falsek = 0n = 0x = cal()Label2.Caption = disp2()Label3.Caption = f()Label4.Caption = redisp()End SubPrivate Sub Combo1_click()year1 = Val(Combo2.Text)month1 = Val(Combo1.Text)day1 = 1Isend = Falsek = 0n = 0x = cal()Picture1.ClsPicture1.Print redisp()Label2.Caption = disp2()End SubPrivate Sub Form_Initialize()'以字符串形式统计农历信息,data(0) = "101001001011" data(1) = "51011001001011" data(2) = "011010100101" data(3) = "011011010100" data(4) = "41010110110101" data(5) = "001010110110" data(6) = "100101010111" data(7) = "20100100101111" data(8) = "010*********" data(9) = "60110010010110" data(10) = "110101001010" data(11) = "111010100101" data(12) = "50110110101001" data(13) = "010*********" data(14) = "001010110110" data(15) = "31001001101110" data(16) = "100100101110" data(17) = "71100100101101" data(18) = "110010010101" data(19) = "110101001010" data(20) = "61101101001010" data(21) = "101101010101" data(22) = "010*********" data(23) = "41010101011011" data(24) = "001001011101" data(25) = "100100101101" data(26) = "21100100101011" data(27) = "101010010101" data(28) = "71011010010101" data(29) = "011011001010" data(30) = "101101010101" data(31) = "50101010110101" data(32) = "010*********" data(33) = "101001011011" data(34) = "30101001010111" data(35) = "010*********" data(36) = "81010100101010" data(37) = "111010010101" data(38) = "011010101010" data(39) = "61010110101010"data(41) = "010*********" data(42) = "41010010101110" data(43) = "101001010111" data(44) = "010*********" data(45) ="31110100100110" data(46) = "110110010101" data(47) = "70101101010101" data(48) = "010*********" data(49) = "100101101101" data(50) = "50100101011101" data(51) = "010*********" data(52) = "101001001101" data(53) = "41101001001101" data(54) = "110100100101" data(55) = "81101010100101" data(56) = "101101010100" data(57) = "101101101010" data(58) = "61001011011010" data(59) = "100101011011" data(60) = "010*********" data(61) = "41010010010111" data(62) = "101001001011" data(63) = "A1011001001011" data(64) = "011010100101" data(65) = "011011010100" data(66) = "61010110110100" data(67) = "101010110110" data(68) = "100101010111" data(69) = "50100100101111" data(70) = "010*********" data(71) = "011001001011" data(72) = "30110101001010" data(73) = "111010100101" data(74) = "80110101100101" data(75) = "010*********" data(76) = "101010110110" data(77) = "51001001101101" data(78) = "100100101110" data(79) = "110010010110" data(80) = "41101010010101" data(81) = "110101001010" data(82) = "110110100101" data(83) = "20101101010101"data(85) = "71010101011011"data(86) = "001001011101"data(87) = "100100101101"data(88) = "51100100101011"data(89) = "101010010101"data(90) = "101101001010"data(91) = "41011010101010"data(92) = "101011010101"data(93) = "90101010110101"data(94) = "010*********"data(95) = "101001011011"data(96) = "60101001010111"data(97) = "010*********"data(98) = "101010010011"data(99) = "40111010010101"year1 = Year(Now)month1 = Month(Now)day1 = Day(Now)x = calLabel1.Caption = disp3()End SubPrivate Sub Form_Load()For j = 0 To 11Combo1.List(j) = j + 1Next jFor i = 0 To 99Combo2.List(i) = i + 1921Next iCombo1.T ext = Combo1.List(Month(Now) - 1) Combo2.Text = Combo2.List(Year(Now) - 1921) tian = "甲乙丙丁戊己庚辛壬癸"di = "子丑寅卯辰巳午未申酉戌亥"Isend = Falsek = 0n = 0year1 = Year(Now)month1 = Month(Now)day1 = 1x = calLabel2.Caption = disp2() '天干地支纪年Form1.ShowPicture1.Print redisp() '显示农历阳历在图片框上Label5.Caption = Year(Now) & "年" & Month(Now) & "月" & Day(Now) & "日"End SubFunction disp1() As String '以汉字形式显示农历信息ri1 = "初一初二初三初四初五初六初七初八初九初十十一十二十三十四十五十六十七十八十九廿十廿一廿二廿三廿四廿五廿六廿七廿八廿九三十"yue = Array("一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "冬", "腊")st = ""st = st + Mid(ri1, 2 * cday - 1, 2)If cday = 1 ThenIf cmonth< 0 Thenst = "闰" &yue(-cmonth - 1)Elsest = yue(cmonth - 1) & "月"End IfEnd Ifdisp1 = stEnd FunctionFunction disp2() As String '天干地支纪年法Dim tmp As Stringtmp = ""tmp = Mid(tian, ((Year(Now) - 4) Mod 10) + 1, 1) + Mid(di, ((Year(Now) - 4) Mod 12) + 1, 1) & "年" disp2 = tmpEnd FunctionFunction disp3() As String '把农历信息以汉字的形式输出ri1 = "初一初二初三初四初五初六初七初八初九初十十一十二十三十四十五十六十七十八十九廿十廿一廿二廿三廿四廿五廿六廿七廿八廿九三十"yue = Array("一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "冬", "腊")If cmonth< 0 Thenst = "闰" &yue(-cmonth - 1) & "月"Elsest = yue(cmonth - 1) & "月"End Ifst = st + Mid(ri1, 2 * cday - 1, 2)disp3 = stEnd FunctionFunction cal() As String '以1921年2月8日为基准点,计算阳历某一天对应的阴历k = 0: n = 0: total = 0date1 = DateSerial(year1, month1, day1)date2 = #2/8/1921#total = DateDiff("d", date2, date1) + 1Dot = data(k)n = IIf(Len(t) = 14, 2, 1)i = (2 * (n - 1) + 13)DoIf total <= 29 + Val(Mid(t, n, 1)) ThenIsend = TrueExit DoEnd Iftotal = total - 29 - Val(Mid(t, n, 1))n = n + 1temp = nIf (n = i) ThenEnd IfLoopIf (Isend = True) ThenExit DoEnd Ifk = k + 1Loopcyear = 1921 + kcmonth = ncday = totalIf Len(data(k)) = 14 ThenIf (cmonth>Val(Mid(data(k), 1, 1)) + 2) Thencmonth = cmonth - 2ElseIf cmonth = Val(Mid(data(k), 1, 1)) + 2 Thencmonth = 2 - cmonthElsecmonth = cmonth - 1End IfEnd IfEnd IfEnd FunctionFunction redisp() As String '把阳历和农历放到一块以字符串的形式的组合到一起redisp = " 日" + "一" + "二" + "三" + "四" + "五" + "六" + Chr(13) + Chr(13)date1 = DateSerial(year1, month1, day1)s = Weekday(date1)Dim a As IntegerFor i = 1 To s - 1redisp = redisp + Space(7)NextFor i = 1 To days(month1)Call addredisp = redisp + " " + Format(i, "!@@@@@") If a Mod 7 = 0 Andi< 8 Thenredisp = redisp + Chr(13)For j = 1 To s - 1redisp = redisp + Space(7)NextFor b = s To 7redisp = redisp + disp1() + " "cday = cday + 1Call addNext bredisp = redisp + Chr(13) + Chr(13)ElseIf (a Mod 7 = 0 Andi>= 8) Thenredisp = redisp + Chr(13)For j = i - 6 Toiredisp = redisp + disp1() + " "cday = cday + 1Call addNext jredisp = redisp + Chr(13) + Chr(13)End IfIf i = days(month1) And a <> 0 Thenredisp = redisp + Chr(13)For j = 1 To aredisp = redisp + disp1() + " "cday = cday + 1Call addNext jEnd Ifa = (a + 1) Mod 7NextEnd FunctionFunction days(month1) As Integer '判断阳历每个月的天数Select Case month1Case 1, 3, 5, 7, 8, 10, 12days = 31Case 4, 6, 9, 11days = 30Case 2If (year1 Mod 4 = 0 And year1 Mod 100 <> 0) Or (year1 Mod 400 = 0) Thendays = 29Elsedays = 28End IfEnd SelectEnd FunctionPrivate Sub Timer1_Timer() '调用系统时间,显示时分秒Label6.Caption = Format(Hour(Time) & ":" & Minute(Time) & ":" & Second(Time), "hh:mm:ss") End SubSub add() '农历的日期加一天之后的农历If Len(data(cyear - 1921)) = 12 ThenIf cday> 29 + Val(Mid(data(cyear - 1921), cmonth, 1)) Then cday = 1: cmonth = cmonth + 1If cmonth = 13 Then cmonth = 1: cyear = cyear + 1 End IfElseIfLen(data(cyear - 1921)) = 14 ThenSelect Case cmonthCase Is < 0If cday> 29 + Val(Mid(data(cyear - 1921), -cmonth + 2, 1)) Then cday = 1: cmonth = -cmonth + 1End IfCase Is <="" 1,="" 1921),="" bdsfid="281" p="">If cday> 29 + Val(Mid(data(cyear - 1921), cmonth + 1, 1)) Then cday = 1: cmonth = cmonth + 1End IfCase Is = V al(Mid(data(cyear - 1921), 1, 1))If cday> 29 + Val(Mid(data(cyear - 1921), cmonth + 1, 1)) Then cday = 1: cmonth = -cmonthEnd IfCase Is >Val(Mid(data(cyear - 1921), 1, 1))If cday> 29 + Val(Mid(data(cyear - 1921), cmonth + 2, 1)) Then cday = 1: cmonth = cmonth + 1End IfEnd SelectEnd IfEnd Sub。

C语言万年历(代码+说明)

C语言万年历(代码+说明)

/*本程序在Microsoft Visual Studio 2010 旗舰版中测试通过*/ #include "stdio.h"#include "stdlib.h"#include "time.h"#include "conio.h"#define KEYUP 72//宏定义键盘的键值(↑)#define KEYDOWN 80//宏定义键盘的键值(↓)#define KEYLEFT 75//宏定义键盘的键值(←)#define KEYRIGHT 77//宏定义键盘的键值(→)//函数声明部分const int isLeap(int year);const int getMonthDays(int year,int month);const int yearDays(int year);void printCalendar(int year,int month);void main(){int year,month;int action = 0;//获取本地当前的年份和月份time_t timep;struct tm *p;time(&timep);p = localtime(&timep);year = p->tm_year+1900;//获取本地当前的年份month = p->tm_mon + 1;//获取本地当前的月份while(1){printf("\t\t %d 年%d 月\n",year,month);printCalendar(year,month);action = getch();system("cls");switch(action){case KEYUP:year++;break;case KEYDOWN:year--;break;case KEYLEFT:month--;if(month < 1){month = 12;}break;case KEYRIGHT:month++;if(month > 12){month = 1;}break;}}}//判断year 是否是润年返回1 为闰年const int isLeap(int year){if(year%4==0&&year%100!=0||year%400==0){ return 1;}else{return 0;}}/*计算year 年的month 月是多少天*返回值:整型,天数*/const int getMonthDays(int year,int month){ switch(month){case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;break;case 4:case 6:case 9:case 11:return 30;break;case 2:if(isLeap(year)){return 29;}else{return 28;}break;default:return 0;break;}}//计算year 年的天数const int yearDays(int year){if(isLeap(year)){return 366;}else{return 365;}}/*判断year 年month 月day 天时星期几*返回值:0,1,2,3,4,5,6*/const int isWeek(int year,int month,int day){ int days = 0;int i;//计算前year 年有多少天for(i=1;i<year;i++){days = days + yearDays(i);}//计算year 年的前month 个月有多少天for(i=1;i<month;i++){days = days + getMonthDays(year,i);}//从公元1 年days = days + day;return days%7;}//按日历的格式打印year 年month 月的日历void printCalendar(int year,int month){const char *week[]= {"日","一","二","三","四","五","六"};int i;int row = 0;for(i=0;i<7;i++){printf("%s\t",week[i]);}printf("\n");//判断year 年month 月1 日时星期几for(i=0;i<isWeek(year,month,1);i++){printf("\t");}for(i=0;i<getMonthDays(year,month);i++){ printf("%d\t",i+1);//如果是星期六就换行打印日期if(isWeek(year,month,i+1) == 6){row ++;if(row == 2){printf(" ↑");}if(row == 3){printf("←→");}if(row == 4){printf(" ↓");}printf("\n\n");}}printf("\n");}CreateDBW制作2012年12月7日。

单行带农历的日期时间代码

单行带农历的日期时间代码

单行带农历的日期时间代码单行带农历的日期时间代码<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>单行带农历的日期时间代码</title></head><body><SCRIPT language=JavaScript><!--function CalConv(){FIRSTYEAR = 1998;LASTYEAR = 2031;today = new Date();SolarYear = today.getFullYear();SolarMonth = today.getMonth() + 1;SolarDate = today.getDate();Weekday = today.getDay();LunarCal = [new tagLunarCal( 27, 5, 3, 43, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1 ), new tagLunarCal( 46, 0, 4, 48, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 ), /* 88 */new tagLunarCal( 35, 0, 5, 53, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 ), /* 89 */new tagLunarCal( 23, 4, 0, 59, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ), new tagLunarCal( 42, 0, 1, 4, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ), new tagLunarCal( 31, 0, 2, 9, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0 ),/* 93 */new tagLunarCal( 39, 0, 5, 20, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 ), new tagLunarCal( 28, 7, 6, 25, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1 ), new tagLunarCal( 48, 0, 0, 30, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1 ), new tagLunarCal( 37, 0, 1, 35, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 ), /* 97 */new tagLunarCal( 25, 5, 3, 41, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ), new tagLunarCal( 44, 0, 4, 46, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 ), new tagLunarCal( 33, 0, 5, 51, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ), new tagLunarCal( 22, 4, 6, 56, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ), /* 101 */new tagLunarCal( 40, 0, 1, 2, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ), new tagLunarCal( 30, 9, 2, 7, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 ), new tagLunarCal( 49, 0, 3, 12, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1 ), new tagLunarCal( 38, 0, 4, 17, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0 ), /* 105 */new tagLunarCal( 27, 6, 6, 23, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1 ), new tagLunarCal( 46, 0, 0, 28, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0 ), new tagLunarCal( 35, 0, 1, 33, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0 ), new tagLunarCal( 24, 4, 2, 38, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 ), /* 109 */new tagLunarCal( 42, 0, 4, 44, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ), new tagLunarCal( 31, 0, 5, 49, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0 ), new tagLunarCal( 21, 2, 6, 54, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 ), new tagLunarCal( 40, 0, 0, 59, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1 ), /* 113 */new tagLunarCal( 28, 6, 2, 5, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 ), new tagLunarCal( 47, 0, 3, 10, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1 ), new tagLunarCal( 36, 0, 4, 15, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1 ),/* 117 */new tagLunarCal( 43, 0, 0, 26, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 ), new tagLunarCal( 32, 0, 1, 31, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0 ), new tagLunarCal( 22, 3, 2, 36, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0 ) ];/* 民國年每月之日數 all by */SolarCal = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];/* 民國年每月之累積日數, 平年與閏年 */SolarDays = [ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 396, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 397 ];if ( SolarYear <= FIRSTYEAR || SolarYear > LASTYEAR ) return 1;sm = SolarMonth - 1;if ( sm < 0 || sm > 11 ) return 2;leap = GetLeap( SolarYear );if ( sm == 1 )d = leap + 28;elsed = SolarCal[sm];if ( SolarDate < 1 || SolarDate > d ) return 3;y = SolarYear - FIRSTYEAR;acc = SolarDays[ leap*14 + sm ] + SolarDate;kc = acc + LunarCal[y].BaseKanChih;Kan = kc % 10;Chih = kc % 12;Age = kc % 60;if ( Age < 22 )Age = 22 - Age;elseAge = 82 - Age;if ( acc <= LunarCal[y].BaseDays ) {y--;LunarYear = SolarYear - 1;leap = GetLeap( LunarYear );sm += 12;acc = SolarDays[leap*14 + sm] + SolarDate; }elseLunarYear = SolarYear;l1 = LunarCal[y].BaseDays;for ( i=0; i<13; i++ ) {l2 = l1 + LunarCal[y].MonthDays[i] + 29;if ( acc <= l2 ) break;l1 = l2;}LunarMonth = i + 1;LunarDate = acc - l1;im = LunarCal[y].Intercalation;if ( im != 0 && LunarMonth > im ) { LunarMonth--;if ( LunarMonth == im ) LunarMonth = -im; }if ( LunarMonth > 12 ) LunarMonth -= 12; today=new Date();function initArray(){this.length=initArray.arguments.lengthfor(var i=0;i<this.length;i++)this[i+1]=initArray.arguments[i] }var d=new initArray("星期日","星期一","星期二","星期三","星期四","星期五","星期六");document.write("", today.getYear(),"年",today.getMonth()+1,"月",today.getDate(),"日&nbsp;",d[today.getDay()+1],"");months = ["一","二","三","四","五","六","七","八","九","十","十一","十二"];days = ["初一","初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"];document.write( "&nbsp;农历"+months[LunarMonth-1]+"月" + days[LunarDate-1] + "");return 0;}/* 求此民國年是否為閏年, 返回 0 為平年, 1 為閏年 */function GetLeap( year ){if ( year % 400 == 0 )return 1;else if ( year % 100 == 0 )return 0;else if ( year % 4 == 0 )return 1;elsereturn 0;}function tagLunarCal( d, i, w, k, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13) {this.BaseDays = d; /* 到民國 1 月 1 日到農曆正月初一的累積日數 */this.Intercalation = i; /* 閏月月份. 0==此年沒有閏月 */this.BaseWeekday = w; /* 此年民國 1 月 1 日為星期幾再減 1 */ this.BaseKanChih = k; /* 此年民國 1 月 1 日之干支序號減 1 */ this.MonthDays = [ m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13 ]; /* 此農曆年每月之大小, 0==小月(29日), 1==大月(30日) */}//--></SCRIPT><a target=_blank href=><FONT color=#2b68a7><SCRIPT>CalConv();</SCRIPT></FONT></a> </body></html>本代码由<a href=/myuserhome.aspx?isowner=1>【荷花小女子】</a>提供。

C语言农历表算法

C语言农历表算法

int i,sum=0; if(nYear%4==0) { for(i=0;i<(nMonth-1);i++) {
sum+=nDaysLeapYear[i]; }
return (sum+nDay+nWeekOfFirstday-1)%7; } else {
for(i=0;i<(nMonth-1);i++) { sum+=nDaysYear[i]; }
nMonthDays=nDaysLeapYear[nMonth-1]; else if(isleapyear==0) nMonthDays=nDaysYear[nMonth-1]; if(i==11) {
while(nDay<1||nDay>nMonthDays) { printf("查询日期 chDate 非法\n"); return 0; }
printf("*********************************\n"); printf(" SUN MON TUE WEN THU FRI STA\n"); for(i=1,j=1;j<=nMonthDays;i++) { if(i<=nWeek+1) printf(" "); else { printf("%4d",j); j++; } if(i%7==0) printf("\n"); } printf("\n********************************\n"); printf("OK!\n"); } main() {

万年历c语言代码讲解

万年历c语言代码讲解

万年历c语言代码讲解摘要:一、万年历C语言代码讲解简介1.万年历的概念及用途2.C语言代码讲解的重要性二、C语言代码基础1.C语言简介2.C语言基本语法3.C语言的数据类型与变量三、万年历C语言代码实现1.计算闰年2.计算月份的天数3.计算日期的星期4.输出万年历四、万年历C语言代码的优化与拓展1.代码性能优化2.功能的拓展与实现五、总结1.万年历C语言代码讲解的意义2.对编程能力的提升正文:一、万年历C语言代码讲解简介万年历是一种记录了公历日期的工具,它可以帮助我们快速查询公历日期对应的农历、节日、提醒等信息。

C语言是一种广泛应用于计算机领域的编程语言,掌握C语言编程对于学习其他编程语言有很大的帮助。

本文将详细讲解万年历C语言代码的实现过程,帮助读者更好地理解C语言编程。

二、C语言代码基础1.C语言简介C语言是一种高级编程语言,由丹尼斯·里奇(Dennis Ritchie)于20世纪70年代在贝尔实验室开发。

C语言具有良好的性能和可移植性,被广泛应用于操作系统、嵌入式系统、硬件驱动等领域。

2.C语言基本语法C语言的基本语法包括变量声明、数据类型、运算符、控制结构、函数等。

了解这些基本语法对于编写C语言代码至关重要。

3.C语言的数据类型与变量C语言的数据类型包括整型、浮点型、字符型等。

变量是存储数据的容器,通过变量名来表示。

声明变量时需要指定变量的数据类型和存储空间。

三、万年历C语言代码实现1.计算闰年闰年是指公历年份可以被4整除但不能被100整除的年份,或者是可以被400整除的年份。

通过编写一个函数,我们可以判断一个年份是否为闰年。

2.计算月份的天数根据公历规定,每个月的天数不同。

通过编写一个函数,我们可以计算指定月份的天数。

3.计算日期的星期通过编写一个函数,我们可以根据公历日期计算对应的星期。

4.输出万年历根据用户输入的日期范围,输出对应的万年历信息。

四、万年历C语言代码的优化与拓展1.代码性能优化在实现万年历C语言代码的过程中,可以通过优化算法、使用更高效的函数等方式提高代码性能。

excel中农历国历的相互转换方法及代码

excel中农历国历的相互转换方法及代码

打开相应的excel表格,按Alt+F11打开VBA编辑器,点击插入—插入模块,将下面代码粘贴上去,点击保存后关闭该窗口。

接着在相应单元格调用下面四个函数即可实现相应的功能了。

适用于1901-2100年间=lunar("2006-11-1") 求阳历2006-11-1日对应的阴历=solar("2006-1-1") 求阴历2006年正月初一对应的阳历=lunarbirth("1975-5-6") 阴历生日:阳历1975年5月6日出生,今年阴历生日时对应的阳历日期=solarbirth("1975-5-6") 阳历生日:阳历1975年5月6日出生,今年阳历生日时对应的阳历日期1.'阴阳历转换和阴阳历生日2.'Version: 1.1 2005-9-13.'Author: James Zhuang4.'Lunar(SolarDate[, Part = 0 | 1 | 2 | 3]) 阳历转换成阴历5.' Part = 0, all; Part = 1, lunar year; Part = 2, lunarmonth; Part = 3, lunar day6.'Solar(LunarDate[, LunarMonth = 0 | 1]) 阴历转换成阳历7.Type ConvDataA8. leapmonth As Integer9. month(1 To 13) As Integer10. sp_month As Integer 'Solar month of Spring Festival11. sp_day As Integer 'Solar day of Spring Festival12.End Type13.Private Function LunarData(q_year) As ConvDataA14. Dim d As Long15. Dim month(1 To 13) As Integer16.'1901-210017.LunarCal = Array(&H4AE53, &HA5748, &H5526BD, &HD2650, &HD9544, &H46AAB9, &H56A4D,&H9AD42, &H24AEB6, &H4AE4A, _18.&H6A4DBE, &HA4D52, &HD2546, &H5D52BA, &HB544E, &HD6A43, &H296D37, &H95B4B,&H749BC1, &H49754, _19.&HA4B48, &H5B25BC, &H6A550, &H6D445, &H4ADAB8, &H2B64D, &H95742, &H2497B7,&H4974A, &H664B3E, _20.&HD4A51, &HEA546, &H56D4BA, &H5AD4E, &H2B644, &H393738, &H92E4B, &H7C96BF,&HC9553, &HD4A48, _21.&H6DA53B, &HB554F, &H56A45, &H4AADB9, &H25D4D, &H92D42, &H2C95B6, &HA954A,&H7B4ABD, &H6CA51, _22.&HB5546, &H555ABB, &H4DA4E, &HA5B43, &H352BB8, &H52B4C, &H8A953F, &HE9552,&H6AA48, &H7AD53C, _23.&HAB54F, &H4B645, &H4A5739, &HA574D, &H52642, &H3E9335, &HD9549, &H75AABE,&H56A51, &H96D46, _24.&H54AEBB, &H4AD4F, &HA4D43, &H4D26B7, &HD254B, &H8D52BF, &HB5452, &HB6A47,&H696D3C, &H95B50, _25.&H49B45, &H4A4BB9, &HA4B4D, &HAB25C2, &H6A554, &H6D449, &H6ADA3D, &HAB651,&H93746, &H5497BB, _26.&H4974F, &H64B44, &H36A537, &HEA54A, &H86B2BF, &H5AC53, &HAB647, &H5936BC,&H92E50, &HC9645, _27.&H4D4AB8, &HD4A4C, &HDA541, &H25AA36, &H56A49, &H7AADBD, &H25D52, &H92D47,&H5C95BA, &HA954E, _28.&HB4A43, &H4B5537, &HAD54A, &H955ABF, &H4BA53, &HA5B48, &H652BBC, &H52B50,&HA9345, &H474AB9, _29.&H6AA4C, &HAD541, &H24DAB6, &H4B64A, &H69573D, &HA4E51, &HD2646, &H5E933A,&HD534D, &H5AA43, _30.&H36B537, &H96D4B, &HB4AEBF, &H4AD53, &HA4D48, &H6D25BC, &HD254F, &HD5244,&H5DAA38, &HB5A4C, _31.&H56D41, &H24ADB6, &H49B4A, &H7A4BBE, &HA4B51, &HAA546, &H5B52BA, &H6D24E,&HADA42, &H355B37, _32.&H9374B, &H8497C1, &H49753, &H64B48, &H66A53C, &HEA54F, &H6B244, &H4AB638,&HAAE4C, &H92E42, _33.&H3C9735, &HC9649, &H7D4ABD, &HD4A51, &HDA545, &H55AABA, &H56A4E, &HA6D43,&H452EB7, &H52D4B, _34.&H8A95BF, &HA9553, &HB4A47, &H6B553B, &HAD54F, &H55A45, &H4A5D38, &HA5B4C,&H52B42, &H3A93B6, _35.&H69349, &H7729BD, &H6AA51, &HAD546, &H54DABA, &H4B64E, &HA5743, &H452738,&HD264A, &H8E933E, _36.&HD5252, &HDAA47, &H66B53B, &H56D4F, &H4AE45, &H4A4EB9, &HA4D4C, &HD1541,&H2D92B5, &HD5349)37.startyear = 190138.ng = LunarCal(q_year - startyear)39. d = &H10000040. LunarData.leapmonth = Int(ng / d)41. ng = ng Mod d42. d = &H8043. mdata = Int(ng / d)44. ng = ng Mod d45. d = &H2046. LunarData.sp_month = Int(ng / d)47. LunarData.sp_day = ng Mod d48. d = &H100049. i = 150. Do51. LunarData.month(i) = 29 + Int(mdata / d)52. mdata = mdata Mod d53. If d = 1 Then Exit Do54. d = d / 255. i = i + 156. Loop57. If LunarData.leapmonth = 0 Then LunarData.month(i) = 058.End Function59.Function lunar(Solar_date As Date, Optional Part As Integer = 0) As String60.'Part = 0, all; Part = 1, lunar year; Part = 2, lunar month; Part = 3, lunar day61.Dim a As ConvDataA62.l_year = Year(Solar_date)63.a = LunarData(l_year)64.sp_date = DateSerial(l_year, a.sp_month, a.sp_day)65.If sp_date > Solar_date Then66. l_year = l_year - 167. a = LunarData(l_year)68. sp_date = DateSerial(l_year, a.sp_month, a.sp_day)69.End If70.l_day = Solar_date - sp_date71.l_month = 172.IS_lunar_leapmonth = False73.y = a.month(l_month)74.Do While l_day >= y75. l_day = l_day - y76. If l_month = a.leapmonth Then IS_lunar_leapmonth = (Not IS_lunar_leapmonth)77. If IS_lunar_leapmonth Then78. y = a.month(13)79. Else80. l_month = l_month + 181. y = a.month(l_month)82. End If83.Loop84.l_day = l_day + 185.lunar = l_year & "-" & l_month & "-" & l_day86.If IS_lunar_leapmonth Then lunar = lunar & "-L"87.lunar = Choose(Part + 1, lunar, l_year, l_month, l_day)88.End Function89.Function solar(Lunar_date, Optional IS_lunar_leapmonth As Integer = 0) As String90.'IS_lunar_leapmonth = 0, No leap month; IS_lunar_leapmonth = 1, is leap month91.Dim a As ConvDataA92.Lunar_date = Split(Lunar_date, "-")93.s_year = Lunar_date(0)94.For Each C In Lunar_date95. If C = "L" Then IS_lunar_leapmonth = 196.Next97.a = LunarData(s_year)98.sp_date = DateSerial(s_year, a.sp_month, a.sp_day)99.If Lunar_date(1) <> a.leapmonth Then IS_lunar_leapmonth = 0100.x = Lunar_date(2)101.tm = Lunar_date(1) + IS_lunar_leapmonth - 1102.For i = 1 To tm103. x = x + a.month(i)104. If i = a.leapmonth And IS_lunar_leapmonth = 0 Then105. x = x + a.month(13)106. End If107.Next108.s_date = sp_date + x - 1109.solar = s_date110.End Function111.Function lunarbirth(Solar_birthday As Date, Optional Inquire_year As Integer) As String112. If Inquire_year = 0 Then113. Inquire_year = Left(lunar(Now), 4)114. lunarbirth = solar(Inquire_year & Mid(lunar(Solar_birthday), 5, 10)) 115. If CDate(lunarbirth) < Now - 1 Then Inquire_year = Inquire_year + 1 116. End If117. lunarbirth = solar(Inquire_year & Mid(lunar(Solar_birthday), 5, 10)) 118.End Function119.Function solarbirth(Solar_birthday As Date, Optional Inquire_year As Integer) As String120. If Inquire_year = 0 Then121. Inquire_year = Year(Now)122. solarbirth = DateSerial(Inquire_year, month(Solar_birthday), Day(Solar_birthday))123. If CDate(solarbirth) < Now - 1 Then Inquire_year = Inquire_year + 1 124. End If125. solarbirth = DateSerial(Inquire_year, month(Solar_birthday), Day(Solar_birthday))126.End Function。

万年历代码c语言

万年历代码c语言

万年历代码c语言万年历是一种实用的日历工具,它可以根据年、月、日来显示当天的日期信息,并可以切换到其他日期来查询对应的日期信息。

在编写万年历的代码时,我们需要考虑输入的年份是否为闰年、每个月的天数、以及每个月第一天是星期几等等。

以下是一份使用C语言编写万年历的参考代码:```c#include <stdio.h>// 判断是否为闰年int isLeapYear(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); }// 获取某年某月的天数int getMonthDays(int year, int month) {int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};if (month == 2 && isLeapYear(year)) {return 29;}return days[month - 1];}// 获取某年某月第一天是星期几int getFirstDayOfWeek(int year, int month) {int day = 1;for (int i = 1800; i < year; i++) {if (isLeapYear(i)) {day = (day + 366) % 7;} else {day = (day + 365) % 7;}}for (int i = 1; i < month; i++) {day = (day + getMonthDays(year, i)) % 7;}return day;}int main() {int year, month;printf("请输入年份:");scanf("%d", &year);printf("请输入月份:");scanf("%d", &month);// 判断输入是否合法if (year < 1800 || month < 1 || month > 12) {printf("输入的年份或月份不合法!\n");return 0;}// 获取某年某月的天数和第一天是星期几int days = getMonthDays(year, month);int firstDayOfWeek = getFirstDayOfWeek(year, month); // 打印万年历printf("日一二三四五六\n");for (int i = 0; i < firstDayOfWeek; i++) {printf(" ");}for (int i = 1; i <= days; i++) {printf("%2d ", i);if ((firstDayOfWeek + i) % 7 == 0) {printf("\n");}}printf("\n");return 0;}```以上代码实现了一个简单的万年历功能,在控制台输出给定年份和月份的月历。

lunarcalendar python用法

lunarcalendar python用法

lunarcalendar python用法lunarcalendar 是一个用于计算农历(也称阴历或月历)的 Python 库。

尽管我无法提供超过500字的详细代码示例(因为这会超出简短回答的范围),但我可以向你展示如何使用这个库的基本方法,并提供一些代码片段来指导你入门。

首先,你需要安装 lunarcalendar 库。

这通常可以通过 pip 命令完成:bashpip install lunarcalendar安装完成后,你可以在 Python 脚本中导入并使用它。

下面是一个简单的示例,展示了如何使用 lunarcalendar 来获取指定公历日期的农历信息:pythonfrom lunarcalendar import LunarCalendarimport datetime# 创建一个 LunarCalendar 实例lc = LunarCalendar()# 获取今天的公历日期today = datetime.date.today()# 使用 LunarCalendar 实例将公历日期转换为农历日期lunar_date = lc.solar_to_lunar(today.year, today.month, today.day)# lunar_date 是一个元组,包含农历的年、月、日、是否闰月以及农历年的天干地支# 输出农历日期print(f"农历日期: {lunar_date[0]}年{lunar_date[1]}月{lunar_date[2]}日")# 你还可以将农历日期转换回公历日期solar_date = lc.lunar_to_solar(lunar_date[0], lunar_date[1], lunar_date[2])print(f"对应的公历日期: {solar_date[0]}-{solar_date[1]}-{solar_date[2]}") 这个示例展示了如何使用 lunarcalendar 库进行基本的农历和公历之间的转换。

单片机万年历程序带农历和闹钟

单片机万年历程序带农历和闹钟

#include < character.h >#include < lcd.h >#include < clock.h >#include < sensor.h>#include < calendar.h >#include < key.h >/*****************************预概念**************************************/#define uchar unsigned char#define uint unsigned int/****************************************************************************/ sbit bell = P2 ^ 0; //概念蜂鸣器端口sbit in = P2 ^ 7; //概念红外检测端口/***************************************************************************** * 名称: Timer0_Service() inturrupt 1* 功能: 中断效劳程序整点报时3声嘟嘟的声音* 入口参数:* 出口参数:*****************************************************************************/ void Timer0_Service() interrupt 1{static uchar count = 0;static uchar flag = 0; //记录鸣叫的次数count = 0;TR0 = 0; //关闭Timer0TH0 = 0x3c;TL0 = 0XB0; //延时50 msTR0 = 1 ; //启动Timer0count ++;if( count == 20 ) //鸣叫1 秒{bell = ~ bell;count = 0;flag ++;}if( flag == 6 ){flag = 0;TR0 = 0; //关闭Timer0}}/****************************************************************************** 名称: Timer2_Servie() interrupt 5* 功能: 中断效劳程序整点报时一分钟* 入口参数:* 出口参数:*****************************************************************************/ void Timer3_Service() interrupt 5{static uchar count;TF2 = 0; //软件清除中断标志count ++;if( in == 1 ){count = 0; //计算清0TR2 = 0; //关闭Timer2bell = 1; //关闭蜂鸣器}if( count == 120 ) // 一分钟后关闭报警{count = 0; //计算清0TR2 = 0; //关闭Timer2bell = 1; //关闭蜂鸣器}}/****************************************************************************** * 函数名称:main()* 功能:* 入口参数:* 出口参数:******************************************************************************* */void main( void ){uchar clock_time[7] = { 0x00, 0x17, 0x12, 0x14, 0x12, 0x08 }; //概念时刻变量秒分时日月年uchar alarm_time[2] = { 0, 0}; //闹钟设置alarm_time[0]: 分钟alarm_time[1] :小时uchar temperature[2]; //概念温度变量temperature[0] 低8位temperature[1] 高8位Lcd_Initial(); //LCD初始化Clock_Initial( clock_time ); //时钟初试化/***********************中断初始化***************************/EA = 1; //开总中断ET0 = 1; //Timer0 开中断ET2 = 1; //Timer2 开中断TMOD = 0x01 ; //Timer0 工作方式1RCAP2H = 0x3c;RCAP2L = 0xb0; //Timer2 延时50 mswhile( 1 ){switch( Key_Scan() ){case up_array: //{Key_Idle();}break;case down_array:{Key_Idle();}break;case clear_array:{Key_Idle();}break;case function_array:{Key_Function( clock_time, alarm_time );}case null:{Clock_Fresh( clock_time ); //时刻刷新Lcd_Clock( clock_time ); //时刻显示Sensor_Fresh( temperature ); //温度更新Lcd_Temperture( temperature ); //温度显示Calendar_Convert( 0 , clock_time );Week_Convert( 0, clock_time );//整点报时if( ( * clock_time == 0x59 ) && ( * ( clock_time + 1 ) == 0x59 ) ){bell = 0;TR2 = 1; //启动Timer2}//闹钟报警if( * alarm_time == * ( clock_time + 1 ) ) //分钟相吻合if( * ( alarm_time + 1 ) == *( clock_time + 2 ) ) //小时相吻合{bell = 0;TR2 = 1; //启动Timer2}}break;}}}#ifndef _SUN_MOON#define _SUN_MOON/*************************************************************************/#define uchar unsigned char#define uint unsigned int/****************************************************************************** *** 名称: get_moon_day(uchar month_p,uint table_addr)* 功能: 读取数据表中农历的大月或小月,若是大月返回1, 小月返回0* 入口参数:* 出口参数:******************************************************************************* **/bit get_moon_day( uchar month_p,uint calendar_address ){uchar temp;switch(month_p){case 1: { temp = year_code[calendar_address] & 0x08; if(temp==0) return(0); else return(1); }case 2: { temp = year_code[calendar_address] & 0x04; if(temp==0) return(0); else return(1); }case 3: { temp = year_code[calendar_address] & 0x02; if(temp==0) return(0); else return(1); }case 4: { temp = year_code[calendar_address] & 0x01; if(temp==0) return(0); else return(1); }case 5: { temp = year_code[calendar_address + 1] & 0x80; if(temp==0) return(0); else return(1); }case 6: { temp = year_code[calendar_address + 1] & 0x40; if(temp==0) return(0); else return(1); }case 7: { temp = year_code[calendar_address + 1] & 0x20; if(temp==0) return(0); else return(1); }case 8: { temp = year_code[calendar_address + 1] & 0x10; if(temp==0) return(0); else return(1); }case 9: { temp = year_code[calendar_address + 1] & 0x08; if(temp==0) return(0); else return(1); }case 10: { temp = year_code[calendar_address + 1] & 0x04; if(temp==0) return(0); else return(1); }case 11: { temp = year_code[calendar_address + 1] & 0x02; if(temp==0) return(0); else return(1); }case 12: { temp = year_code[calendar_address + 1] & 0x01; if(temp==0) return(0); else return(1); }case 13: { temp = year_code[calendar_address + 2] & 0x80; if(temp==0) return(0); else return(1); }}}/*************************************************************************** 名称: void Calendar_Convert( uchar * clock_time )* 功能: 输入BCD的阳历数据,输出BCD阴历数据( 1901 - 2099 )* 入口参数: c_flag:阳历的世纪标志clock_time: 时钟地址* 出口参数: 无* 说明: c_flag = 0 :21世纪c_flag = 1 :19世纪*****************************************************************************/ void Calendar_Convert( uchar c_flag, uchar * clock_time ){bit flag_month, flag_year;uchar year, month, day, month_point; //概念年月天uchar temp1, temp2, temp3;uint calendar_address; //概念农历地址uint day_number;uchar clock_moon[3]; //概念阴历clock_time += 3; //指向日day = ( * clock_time >> 4 ) * 10 + ( *clock_time & 0x0f ); //BCD转换十进制clock_time ++; //指向月month = ( * clock_time >> 4 ) * 10 + ( * clock_time & 0x0f ); //BCD转换十进制clock_time ++; //指向年year = ( * clock_time >> 4 ) * 10 + ( * clock_time & 0x0f ); //BCD转换十进制//定位日历地址if( c_flag == 0 )calendar_address = ( year + 99 ) * 3;elsecalendar_address = ( year - 1 ) * 3;//春节(正月初一)所在的阳历月份temp1 = year_code[ calendar_address + 2 ] & 0x60; //Bit6~~Bit5:春节所在的阳历月份temp1 >>= 5 ;//春节(正月初一)所在的阳历日期temp2 = year_code[ calendar_address + 2 ] & 0x1f; //Bit4~~Bit0:春节所在的阳历日期//计算春节(正月初一)离昔时元旦{ 1月1日(阳历) }的天数;春节只会在阳历的1月或2月if( temp1 == 1 )temp3 = temp2 - 1;elsetemp3 = temp2 + 31 - 1;//计算阳历月离昔时元旦{ 1月1日(阳历) }的天数if( month < 10 )day_number = day_code1[ month - 1 ] + day - 1;elseday_number = day_code2[ month - 10 ] + day - 1;//若是阳历的月大于2 且该年的2月为闰月,天数加1//闰年指的确实是阳历有闰日或阴历有闰月的一年;//阳历四年一闰,在二月加一天,这一天叫做闰日://农历三年一闰,五年两闰,十九年七闰,每逢闰年所加的一个月叫做闰月。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
if ((yyyy > 1901) && (CnDateofDate(new Date((yyyy - 1)+"/12/31")) < 0)){
ResultMonth = - CnMonth[0];}
else {ResultMonth = CnMonth[0];}
ResultDay = CnBeginDay + DaysCount;
var Dizhi=new Array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥");
return Tiangan[YYYY%10]+Dizhi[YYYY%12];
}
function CnDateofDateStr(DateGL){
if(CnMonthofDate(DateGL)=="零月") return "请调整您的计算机日期!";
0x87,0x6a,0x57,0x04,0x12,0x75,0x2b,0x00,0x1d,0xb6,0x95,0x00,0x8a,0xad,0x55,0x02,
0x15,0x55,0xaa,0x00,0x82,0x55,0x6c,0x07,0x0d,0xc9,0x76,0x00,0x17,0x64,0xb7,0x00,
CnDaysCount+= CnMonthDays[I];
I++;
}
ResultMonth = CnMonth[I];
ResultDay = DaysCount - CnDaysCount;
}
if (ResultMonth > 0){
return ResultMonth * 100 + ResultDay;}
DDDD = DDDD + " " + d[today.getDay()];
DDDD = DDDD+ " " + (CnDateofDateStr(today));
//DDDD = DDDD+ " " + SolarTerm(today);
document.write(DDDD);
}
function DaysNumberofDate(DateGL){
CnMonth[15 - I + 1] = - LeapMonth;}
else{
if (CnMonth[15 - I] < 0 ){CnMonth[15 - I + 1] = - CnMonth[15 - I] + 1;}
else {CnMonth[15 - I + 1] = CnMonth[15 - I] + 1;}
var Tiangan=new Array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸");
//var Dizhi=new Array("子(鼠)","丑(牛)","寅(虎)","卯(兔)","辰(龙)","巳(蛇)",
//"午(马)","未(羊)","申(猴)","酉(鸡)","戌(狗)","亥(猪)");
var mm=DateGL.getMonth()+1;
var dd=DateGL.getDate();
if(yyyy<100) yyyy+=1900;
if ((yyyy < 1997) || (yyyy > 2020)){
return 0;
}
Bytes[0] = CnData[(yyyy - 1997) * 4];
"清明","谷雨","立夏","小满","芒种","夏至",
"小暑","大暑","立秋","处暑","白露","秋分",
"寒露","霜降","立冬","小雪","大雪","冬至");
var DifferenceInMonth=new Array(
0x86,0xe4,0xae,0x05,0x11,0xea,0x56,0x00,0x1b,0x6d,0x2a,0x00,0x88,0x5a,0xaa,0x04,
0x14,0xad,0x55,0x00,0x81,0xaa,0xd5,0x09,0x0b,0x52,0xea,0x00,0x16,0xa9,0x6d,0x00,
1306935,1297380,1286865,1277730,1274550,1271556);
var DifferenceInYear=31556926;
if (CnMonth[15 - I + 1] > 12 ){ CnMonth[15 - I + 1] = 1;}
}
}
DaysCount = DaysNumberofDate(DateGL) - 1;
if (DaysCount <= (CnMonthDays[0] - CnBeginDay)){
0x84,0xa9,0x5d,0x06,0x0f,0xd4,0xae,0x00,0x1a,0xea,0x4d,0x00,0x87,0xba,0x55,0x04
);
var CnMonth=new Array();
var CnMonthDays=new Array();
var CnBeginDay;
function CnDayofDate(DateGL){
var CnDayStr=new Array("零",
"初一", "初二", "初三", "初四", "初五",
"初六", "初七", "初八", "初九", "初十",
"十一", "十二", "十三", "十四", "十五",
Bytes[1] = CnData[(yyyy - 1997) * 4 + 1];
Bytes[2] = CnData[(yyyy - 1997) * 4 + 2];
Bytes[3] = CnData[(yyyy - 1997) * 4 + 3];
if ((Bytes[0] & 0x80) != 0) {CnMonth[0] = 12;}
"十六", "十七", "十八", "十九", "二十",
"廿一", "廿二", "廿三", "廿四", "廿五",
"廿六", "廿七", "廿八", "廿九", "三十");
var Day;
Day = (Math.abs(CnDateofDate(DateGL)))%100;
if(YYYY<100) YYYY+=1900;
if(CnMM>MM) YYYY--;
YYYY-=1864;
return CnEra(YYYY)+"年";
}
function CnMonthofDate(DateGL){
var CnMonthStr=new Array("零","正","二","三","四","五","六","七","八","九","十","冬","腊");
else {CnMonth[0] = 11;}
CnBeginDay = (Bytes[0] & 0x7f);
CnMonthData = Bytes[1];
CnMonthData = CnMonthData << 8;
CnMonthData = CnMonthData | Bytes[2];
LeapMonth = Bytes[3];
for (I=15;I>=0;I--){
CnMonthDays[15 - I] = 29;
if (((1 << I) & CnMonthData) != 0 ){
CnMonthDays[15 - I]++;}
if (CnMonth[15 - I] == LeapMonth ){
相关文档
最新文档