万年历代码,万年历代码java
万年历查询程序. C语言代码
除了天数差计算,基本上是完成了你所提出的功能(天数差计算其实已经提供了年内序数计算方方法,可以在此基础上完善即可)。包含星期计算、公历转农历、农历转公历、节气查询。数据与算法均为原创,绝非网上复制而来。附件中有源代码,同时附带农历数据提取工具,可提取1600到7000年之间的任意年份区间,提取后的数据为压缩数据,占用空间小,同时数据包含数九、三伏、入梅和出梅,非常适合写一份完整的万年历。
部分核心算法函数如下:
//判断闰年,参数:年份,返回值:0-平年,1-闰年
int?IsLeapYear(int?iYear);
//计算日期在年内的序数,参数:年,月,日,年内序数,返回值:0-失败,1-成功
int?GetDaysNumInYear(int?iYear,?int?iMonth,?int?iDay,int?*nDays);
//从年内序数计算月、日,参数:年,年内序数,月,日,返回值:0-失败,1-成功
int?GetDateFromDays(int?iYear,?int?nDays,?int?*iMonth,?int?*iDay);
//检验年、月、日的合法性,参数:年,月,日,返回值:0-失败,1-成功
int?DateCheck(int?iYear,int?iMonth,int?iDay);
//获取农历新年的公历年内序数,参数:农历年,返回值:农历新年的公历年内序数
int?LunarGetNewYearOrdinal(int?iLunarYear);
//获取农历月的天数,参数:农历年,农历月,是否为闰月,返回值:该农历月的天数,为0代表参数无效
int?LunarGetDaysofMonth(int?iLunarYear,int?iLunarMonth,int?IsLeapMonth);
//展开大小月数据表(某一年的),参数:农历年,从上一年十一月开始到当前年份(闰)十二月的每月天数,返回值:0-失败,1-成功
int?LunarExpandDX(int?iLunarYear,int?iDayOfMonth[15]);
//获取农历某一年的闰月情况,参数:农历年,返回值,该年的闰月月份,0表示无闰月
int?LunarGetLeapMonth(int?iLunarYear);
//公历转农历,参数:公历年、月、日,农历年、月、日,是否为闰月,返回值:0-失败,1-成功
int?Gongli2Nongli(int?iYear,int?iMonth,int?iDay,int?*iLunarYear,int?*iLunarMonth,int?*iLunarDay,int?*iIsLeapMonth);
//农历转公历,参数:家历年、月、日,是否为闰月,公历年、月、日,返回值:0-失败,1-成功
int?Nongli2Gongli(int?iLunarYear,int?iLunarMonth,int?iLunarDay,int?iIsLeapMonth,int?*iYear,int?*iMonth,int?*iDay);
//得到指定年份的节气信息,首个是小寒
int?GetJieQi(int?iYear,int?uMonth,unsigned?int?uJieQi[2]);
//计算星期
unsigned?int?GetDayOfWeek(int?iYear,int?uMonth,int?uDay);
源代码请看
吧。提取码:ooj7

用C语言怎么编写万年历
1、首先下载安装Notepad++,这是一款免费的且能够编辑C语言的软件。
2、然后下载安装tdm-gcc,这是为了给电脑配置环境变量,以便能够编译C语言的。
3、在安装完以上两款软件后,还要配置一下环境变量。
4、然后开始编辑C语言万年历,首先要判断一个年份是闰年还是平年,用一个子程序来做:
5、然后就开始写主程序:首先用scanf得到一个年份,在判断这个年份是平年还是闰年后用printf在CMD中打出来。
6、在编写完成后,在Notepad++界面下按下F5,在输入框中输入:
cmd /k gcc -o "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" "$(FULL_CURRENT_PATH)" CLS "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" PAUSE EXIT
7、最后点击运行,会弹出CMD,在里面输入年份后回车:例如输入2017,然后回车,就会生成2017年的万年历了!
用vb编写万年历小程序
用VB做万年历,非常关键点就是农历写法,参考代码如下:
#Region " 返回农历 "
'返回农历
'cCalendar.MaxSupportedDateTime 返回支持的最大日期,即2101-1-28
'cCalendar.MinSupportedDateTime 返回支持的最小日期,即190-2-19
Private cCalendar As New System.Globalization.ChineseLunisolarCalendar
Public Function PubFunGet_CNDate(ByVal sDateTime As Date) As String
cCalendar = New System.Globalization.ChineseLunisolarCalendar
Dim lyear As Integer = cCalendar.GetYear(sDateTime)
Dim lmonth As Integer = cCalendar.GetMonth(sDateTime)
Dim lday As Integer = cCalendar.GetDayOfMonth(sDateTime)
Dim lweek As Integer = cCalendar.GetDayOfWeek(sDateTime)
'获取闰月, 0 则表示没有闰月
Dim leapMonth As Integer = cCalendar.GetLeapMonth(lyear)
Dim isleap As Boolean = False
If (leapMonth 0) Then
If (leapMonth = lmonth) Then
'闰月
isleap = True
lmonth = lmonth - 1
ElseIf (lmonth leapMonth) Then
lmonth = lmonth - 1
End If
End If
Return String.Concat(GetLunisolarYear(lyear), IIf(isleap = True, "闰年", "年"), GetLunisolarMonth(lmonth), "月", GetLunisolarDay(lday))
End Function
'十天干
Private tiangan As String() = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}
'十二地支
Private dizhi As String() = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}
'十二生肖
Private shengxiao As String() = {"鼠", "牛", "虎", "免", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"}
'农历月
Private months As String() = {"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二(腊)"}
'农历日
Private days1 As String() = {"初", "十", "廿", "三"}
Private days As String() = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}
'返回农历年(天干 地支 生肖)
Private Function GetLunisolarYear(ByVal year As Integer) As String
GetLunisolarYear = ""
If (year 3) Then
Dim tgIndex As Integer = (year - 4) Mod 10
Dim dzIndex As Integer = (year - 4) Mod 12
Return tiangan(tgIndex) dizhi(dzIndex) "[" shengxiao(dzIndex) "]"
End If
'无效的年份!
End Function
'返回生肖
Private Function GetShengXiao(ByVal sDateTime As Date) As String
Return shengxiao(cCalendar.GetTerrestrialBranch(cCalendar.GetSexagenaryYear(sDateTime)) - 1)
End Function
'返回农历月
Private Function GetLunisolarMonth(ByVal month As Integer) As String
GetLunisolarMonth = ""
If (month 13 AndAlso month 0) Then
Return months(month - 1)
End If
'无效的月份!
End Function
'返回农历日
Private Function GetLunisolarDay(ByVal day As Integer) As String
GetLunisolarDay = ""
If (day 0 AndAlso day 32) Then
If (day 20 AndAlso day 30) Then
Return String.Concat(days1((day - 1) \ 10), days((day - 1) Mod 10))
Else
Return String.Concat(days((day - 1) \ 10), days1(1))
End If
End If
'无效的日!
End Function
#End Region
求一个java swing带界面的万年历代码
按照你的要求编写的Java swing 带界面的万年历代码如下
//日历
import?java.awt.BorderLayout;
import?java.awt.Color;
import?java.awt.Font;
import?java.awt.GridLayout;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.util.Calendar;
import?javax.swing.BorderFactory;
import?javax.swing.JButton;
import?javax.swing.JFrame;
import?javax.swing.JLabel;
import?javax.swing.JPanel;
public?class?CCI?extends?JFrame?implements?ActionListener{
?JButton?jb1=new?JButton("");
?JButton?jb2=new?JButton("");
?JButton?jb3=new?JButton("");
?JButton?jb4=new?JButton("");
?JPanel?jp1=new?JPanel();
?JPanel?jp2=new?JPanel();
?JPanel?jp3=new?JPanel();
?JPanel?jp4=new?JPanel();
?JLabel?jl1=new?JLabel();
?JLabel?jl2=new?JLabel();
?JLabel[]jl=new?JLabel[49];
?String?[]week={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
?Calendar?c=Calendar.getInstance();
?int?year,month,day;
?int?nowyear,nowmonth,nowday;
?CCI(){
??super("简单日历");
??nowyear=c.get(Calendar.YEAR);
??nowmonth=c.get(Calendar.MONTH)+1;
??nowday=c.get(Calendar.DAY_OF_MONTH);
??year=nowyear;
??month=nowmonth;
??day=nowday;
??String?s=year+"年"+month+"月";
??jl1.setForeground(Color.RED);
??jl1.setFont(new?Font(null,Font.BOLD,20));
??jl1.setText(s);
??jb1.addActionListener(this);
??jb2.addActionListener(this);
??jb3.addActionListener(this);
??jb4.addActionListener(this);
??jp1.add(jb1);jp1.add(jb2);jp1.add(jl1);jp1.add(jb3);jp1.add(jb4);
??jp2.setLayout(null);
??createMonthPanel();
??jp2.add(jp3);
??jl2.setFont(new?Font(null,Font.BOLD,20));
??jl2.setText("今天是"+nowyear+"年"+nowmonth+"月"+nowday+"日");
??jp4.add(jl2);
??add(jp1,BorderLayout.NORTH);
??add(jp2,BorderLayout.CENTER);
??add(jp4,BorderLayout.SOUTH);
??setSize(500,500);
??setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
??setLocationRelativeTo(null);
??setVisible(true);
?}
?@Override
?public?void?actionPerformed(ActionEvent?ae)?{
??if(ae.getSource()==jb1){
???year=year-1;
???String?s=year+"年"+month+"月";
???jl1.setText(s);
???jp3.removeAll();
???createMonthPanel();
???jp3.validate();
??}
??if(ae.getSource()==jb2){
???if(month==1){
????year=year-1;
????month=12;
???}else{
????month=month-1;
???}
???String?s=year+"年"+month+"月";
???jl1.setText(s);
???jp3.removeAll();
???createMonthPanel();
???jp3.validate();
??}
??if(ae.getSource()==jb3){
???if(month==12){
????year=year+1;
????month=1;
???}else{
????month=month+1;
???}
???String?s=year+"年"+month+"月";
???jl1.setText(s);
???jp3.removeAll();
???createMonthPanel();
???jp3.validate();
??}
??if(ae.getSource()==jb4){
???year=year+1;
???String?s=year+"年"+month+"月";
???jl1.setText(s);
???jp3.removeAll();
???createMonthPanel();
???jp3.validate();
??}
?}
?public?static?void?main(String[]?args)?{
??new?CCI();
?}
?public?int?getMonthDays(int?year,?int?month)?{?
??switch?(month)?{
???case?1:?
???case?3:?
???case?5:?
???case?7:
???case?8:?
???case?10:?
???case?12:
????return?31;?
???case?2:?
????if?((year%4==0year%100!=0)||year%400==0)?{?
?????return?29;?
????}?else?{?
?????return?28;?
????}?
???default:?
????return?30;?
??}?
?}?
?public?void?createMonthPanel(){
??c.set(year,?month-1,?getMonthDays(year,month));
??int?weekOfMonth=c.get(Calendar.WEEK_OF_MONTH);
??if(weekOfMonth==6){
???jp3.setLayout(new?GridLayout(7,7));
???jp3.setBounds(50,?20,?420,?350);
??}else{
???jp3.setLayout(new?GridLayout(6,7));
???jp3.setBounds(50,?20,?420,?300);
??}
??jp3.setBorder(BorderFactory.createEtchedBorder());
??for(int?i=0;i7;i++){
???jl[i]=new?JLabel(week[i],JLabel.CENTER);
???jl[i].setFont(new?Font(null,Font.BOLD,20));
???jl[i].setBorder(BorderFactory.createEtchedBorder());
???jp3.add(jl[i]);
??}
??c.set(year,?month-1,?1);
??int?emptyFirst=c.get(Calendar.DAY_OF_WEEK)-1;
??int?daysOfMonth=getMonthDays(year,month);
??for(int?i=6+emptyFirst;i=7;i--){
???int?intyear=year;
???int?intmonth=month;
???if(intmonth==1){
????intyear=intyear-1;
????intmonth=12;
???}else{
????intmonth=intmonth-1;
???}
???int?intdays=getMonthDays(intyear,intmonth);
???jl[i]=new?JLabel((intdays+7-i)+"",JLabel.CENTER);
???jl[i].setFont(new?Font(null,Font.BOLD,20));
???jl[i].setForeground(Color.GRAY);
???jl[i].setBorder(BorderFactory.createEtchedBorder());
???jp3.add(jl[i]);
??}
??for(int?i=7+emptyFirst;idaysOfMonth+7+emptyFirst;i++){
???jl[i]=new?JLabel((i-7-emptyFirst+1)+"",JLabel.CENTER);
???jl[i].setFont(new?Font(null,Font.BOLD,20));
???if((i+1)%7==0?||?(i+1)%7==1){
????jl[i].setForeground(Color.RED);
???}else?if((i-7-emptyFirst+1)==nowdaymonth==nowmonthyear==nowyear)
????jl[i].setForeground(Color.BLUE);
???else
????jl[i].setForeground(Color.BLACK);
???
???jl[i].setBorder(BorderFactory.createEtchedBorder());
???jp3.add(jl[i]);
??}
??if(weekOfMonth==6)
???for(int?i=48;i=daysOfMonth+emptyFirst+7;i--){
????jl[i]=new?JLabel((49-i)+"",JLabel.CENTER);
????jl[i].setFont(new?Font(null,Font.BOLD,20));
????jl[i].setForeground(Color.GRAY);
????jl[i].setBorder(BorderFactory.createEtchedBorder());
????jp3.add(jl[i]);
???}
??else
???for(int?i=41;i=daysOfMonth+emptyFirst+7;i--){
????jl[i]=new?JLabel((42-i)+"",JLabel.CENTER);
????jl[i].setFont(new?Font(null,Font.BOLD,20));
????jl[i].setForeground(Color.GRAY);
????jl[i].setBorder(BorderFactory.createEtchedBorder());
????jp3.add(jl[i]);
???}
?}
}
万年历的一段代码 谁能解释一下 怎么算的???
这种算法是粗略的算法,第一行是算节日的年月日时分秒毫秒。虽然算到毫秒,实际上由于地球的运动在太阳系中有差异,分钟都会不太准。这个节气从一九零零年一月六号二时零五分算起。估计当年元月六号是春分吧。
第二行就是将计算出来毫秒数转换为北京时间。
数组里面是由于地球轨道椭圆,所以数值是一些计算过后的粗略毫秒数。用于计算节气。
这个算法是粗略的,在一百年之内有时候节气会有一天的误差。