C语言公历转农历写法

合集下载

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;
{

公历转换成农历c语言函数

公历转换成农历c语言函数

公历转换成农历c语言函数在进行农历与公历的转换时,使用C语言编写一个函数可以很方便地实现这一功能。

本文将为您介绍一个简单而有效的公历转换成农历的C语言函数。

函数名称:solarToLunar功能:将公历日期转换成农历日期输入参数:int year(公历年份),int month(公历月份),int day (公历日)返回值:char*(农历日期)```c#include<stdio.h>#include<stdlib.h>// 农历数据结构体typedef struct LunarDate {int year;int month;int day;} LunarDate;// 公历转换成农历函数char* solarToLunar(int year, int month, int day) {/* 在这里编写您的代码 */}int main() {int year, month, day;printf("请输入公历年份:");scanf("%d", &year);printf("请输入公历月份:");scanf("%d", &month);printf("请输入公历日期:");scanf("%d", &day);char* lunarDate = solarToLunar(year, month, day); printf("农历日期:%s\n", lunarDate);free(lunarDate); // 释放内存return 0;}```在程序中,我们使用了一个结构体LunarDate来表示农历日期,它包含了年、月、日三个变量。

函数solarToLunar负责将公历日期转换成农历日期,并以字符串形式返回。

接下来,我们需要在函数solarToLunar中编写转换逻辑。

公历、农历互相转换函数

公历、农历互相转换函数

公历、农历互相转换函数'公历、农历互相转换模块'原创:互联网'修正:阿勇 2005/1/12'// 农历数据定义 //'先以 H2B 函数还原成长度为 18 的字符串,其定义如下:'前12个字节代表1-12月:1为大月,0为小月;压缩成十六进制(1-3位)'第13位为闰月的情况,1为大月30天,0为小月29天;(4位) '第14位为闰月的月份,如果不是闰月为0,否则给出月份(5位) '最后4位为当年农历新年的公历日期,如0131代表1月31日;当作数值转十六进制(6-7位)'农历常量(1899~2100,共202年)Private Const ylData = "AB500D2,4BD0883," _&"4AE00DB,A5700D0,54D0581,D2600D8,D9500CC,655147D,56A0 0D5,9AD00CA,55D027A,4AE00D2," _&"A5B0682,A4D00DA,D2500CE,D25157E,B5500D6,56A00CC,ADA 027B,95B00D3,49717C9,49B00DC," _&"A4B00D0,B4B0580,6A500D8,6D400CD,AB5147C,2B600D5,9570 0CA,52F027B,49700D2,6560682," _&"D4A00D9,EA500CE,6A9157E,5AD00D6,2B600CC,86E137C,92E0 0D3,C8D1783,C9500DB,D4A00D0," _"D8A167F,B5500D7,56A00CD,A5B147D,25D00D5,92D00CA,D2B 027A,A9500D2,B550781,6CA00D9," _&"B5500CE,535157F,4DA00D6,A5B00CB,457037C,52B00D4,A9A08 83,E9500DA,6AA00D0,AEA0680," _&"AB500D7,4B600CD,AAE047D,A5700D5,52600CA,F260379,D950 0D1,5B50782,56A00D9,96D00CE," _&"4DD057F,4AD00D7,A4D00CB,D4D047B,D2500D3,D550883,B54 00DA,B6A00CF,95A1680,95B00D8," _&"49B00CD,A97047D,A4B00D5,B270ACA,6A500DC,6D400D1,AF4 0681,AB600D9,93700CE,4AF057F," _&"49700D7,64B00CC,74A037B,EA500D2,6B50883,5AC00DB,AB60 0CF,96D0580,92E00D8,C9600CD," _&"D95047C,D4A00D4,DA500C9,755027A,56A00D1,ABB0781,25D0 0DA,92D00CF,CAB057E,A9500D6," _&"B4A00CB,BAA047B,B5500D2,55D0983,4BA00DB,A5B00D0,5171 680,52B00D8,A9300CD,795047D," _&"6AA00D4,AD500C9,5B5027A,4B600D2,96E0681,A4E00D9,D260 0CE,EA6057E,D5300D5,5AA00CB," _&"76A037B,96D00D3,4AB0B83,4AD00DB,A4D00D0,D0B1680,D25 00D7,D5200CC,DD4057C,B5A00D4," _"56D00C9,55B027A,49B00D2,A570782,A4B00D9,AA500CE,B251 57E,6D200D6,ADA00CA,4B6137B," _&"93700D3,49F08C9,49700DB,64B00D0,68A1680,EA500D7,6AA00 CC,A6C147C,AAE00D4,92E00CA," _&"D2E0379,C9600D1,D550781,D4A00D9,DA400CD,5D5057E,56A0 0D6,A6C00CB,55D047B,52D00D3," _&"A9B0883,A9500DB,B4A00CF,B6A067F,AD500D7,55A00CD,ABA0 47C,A5A00D4,52B00CA,B27037A," _&"69300D1,7330781,6AA00D9,AD500CE,4B5157E,4B600D6,A5700 CB,54E047C,D1600D2,E960882," _&"D5200DA,DAA00CF,6AA167F,56D00D7,4AE00CD,A9D047D,A2D 00D4,D1500C9,F250279,D5200D1"Private Const ylMd0 = "初一初二初三初四初五初六初七初八初九初十十一十二十三十四十五" _& "十六十七十八十九二十廿一廿二廿三廿四廿五廿六廿七廿八廿九三十 "Private Const ylMn0 = "正二三四五六七八九十冬腊"Private Const ylTianGan0 = "甲乙丙丁戊已庚辛壬癸"Private Const ylDiZhi0 = "子丑寅卯辰巳午未申酉戌亥"Private Const ylShu0 = "鼠牛虎兔龙蛇马羊猴鸡狗猪"'公历日期转农历Function GetYLDate(ByVal strDate As String) As StringOn Error GoTo aErrIf Not IsDate(strDate) Then Exit FunctionDim setDate As Date, tYear As Integer, tMonth As Integer, tDay As IntegersetDate = CDate(strDate)tYear = Year(setDate): tMonth = Month(setDate): tDay = Day(setDate)'如果不是有效有日期,退出If tYear > 2100 Or tYear < 1900 Then Exit FunctionDim daList() As String * 18, conDate As Date, thisMonths As StringDim AddYear As Integer, AddMonth As Integer, AddDay As Integer, getDay As IntegerDim YLyear As String, YLShuXing As StringDim dd0 As String, mm0 As String, ganzhi(0 To 59) As String * 2Dim RunYue As Boolean, RunYue1 As Integer, mDays As Integer, i As Integer'加载2年内的农历数据ReDim daList(tYear - 1 To tYear)daList(tYear - 1) = H2B(Mid(ylData, (tYear - 1900) * 8 + 1, 7)) daList(tYear) = H2B(Mid(ylData, (tYear - 1900 + 1) * 8 + 1, 7))AddYear = tYearinitYL:AddMonth = CInt(Mid(daList(AddYear), 15, 2))AddDay = CInt(Mid(daList(AddYear), 17, 2))conDate = DateSerial(AddYear, AddMonth, AddDay) '农历新年日期getDay = DateDiff("d", conDate, setDate) + 1 '相差天数If getDay < 1 Then AddYear = AddYear - 1: GoTo initYLthisMonths = Left(daList(AddYear), 14)RunYue1 = Val("&H" & Right(thisMonths, 1)) '闰月月份If RunYue1 > 0 Then'有闰月thisMonths = Left(thisMonths, RunYue1) & Mid(thisMonths, 13, 1) & Mid(thisMonths, RunYue1 + 1)End IfthisMonths = Left(thisMonths, 13)For i = 1 To 13 '计算天数mDays = 29 + CInt(Mid(thisMonths, i, 1))If getDay > mDays ThengetDay = getDay - mDaysElseIf RunYue1 > 0 ThenIf i = RunYue1 + 1 Then RunYue = TrueIf i > RunYue1 Then i = i - 1End IfAddMonth = iAddDay = getDayExit ForEnd IfNextdd0 = Mid(ylMd0, (AddDay - 1) * 2 + 1, 2)mm0 = Mid(ylMn0, AddMonth, 1) + "月"For i = 0 To 59ganzhi(i) = Mid(ylTianGan0, (i Mod 10) + 1, 1) + Mid(ylDiZhi0, (i Mod 12) + 1, 1)Next iYLyear = ganzhi((AddYear - 4) Mod 60)YLShuXing = Mid(ylShu0, ((AddYear - 4) Mod 12) + 1, 1)If RunYue Then mm0 = "闰" & mm0GetYLDate = "农历" & YLyear & "(" & YLShuXing & ")年" & mm0 & dd0aErr:End Function'农历转公历日期'若 secondMonth 为真,则当 tMonth 是闰月时,取第二个月Function GetDate(ByVal tYear As Integer, tMonth As Integer, tDay As Integer, Optional secondMonth As Boolean = False) AsStringOn Error GoTo aErrIf tYear > 2100 Or tYear < 1899 Or tMonth > 12 Or tMonth < 1 Or tDay > 30 Or tDay < 1 Then Exit FunctionDim thisMonths As String, ylNewYear As Date, toMonth As IntegerDim mDays As Integer, RunYue1 As Integer, i As IntegerthisMonths = H2B(Mid(ylData, (tYear - 1899) * 8 + 1, 7))If tDay > 29 + CInt(Mid(thisMonths, tMonth, 1)) Then Exit FunctionylNewYear = DateSerial(tYear, CInt(Mid(thisMonths, 15, 2)), CInt(Mid(thisMonths, 17, 2))) '农历新年日期thisMonths = Left(thisMonths, 14)RunYue1 = Val("&H" & Right(thisMonths, 1)) '闰月月份toMonth = tMonth - 1If RunYue1 > 0 Then'有闰月thisMonths = Left(thisMonths, RunYue1) & Mid(thisMonths, 13, 1) & Mid(thisMonths, RunYue1 + 1)If tMonth > RunYue1 Or(secondMonth And tMonth = RunYue1) Then toMonth = tMonthEnd IfthisMonths = Left(thisMonths, 13)mDays = 0For i = 1 To toMonthmDays = mDays + 29 + CInt(Mid(thisMonths, i, 1))NextmDays = mDays + tDayGetDate = ylNewYear + mDays - 1aErr:End Function'将压缩的阴历字符还原Private Function H2B(ByVal strHex As String) As StringDim i As Integer, i1 As Integer, tmpV As StringConst hStr = "0123456789ABCDEF"Const bStr = "000000010010001101000101011001111000100110101011110 0110111101111"tmpV = UCase(Left(strHex, 3))'十六进制转二进制For i = 1 To Len(tmpV)i1 = InStr(hStr, Mid(tmpV, i, 1))H2B = H2B & Mid(bStr, (i1 - 1) * 4 + 1, 4)NextH2B = H2B & Mid(strHex, 4, 2)'十六进制转十进制H2B = H2B & "0" & CStr(Val("&H" & Right(strHex, 2)))End Function公历转农历示例:=GetYLDate("2009-5-24") 返回2009年5月24日的农历日期:农历已丑(牛)年五月初一=GetYLDate("2009-6-23") 返回2009年6月23日的农历日期:农历已丑(牛)年闰五月初一农历转公历示例:=GetDate(2009,5,1) 返回2009年五月初一的公历日期:2009-5-24=GetDate(2009,5,1,1) 返回2009年闰五月初一的公历日期:2009-6-23。

C51写的公历转农历和星期

C51写的公历转农历和星期
0x66,0x4B,0x3e, //1930
0x0d,0x4A,0x51, //1931
0x0e,0xA5,0x46, //1932
0x56,0xd4,0xBA, //1933
0x05,0xAd,0x4e, //1934
0x02,0xB6,0x44, //1935
0x39,0x37,0x38, //1936
/*
函数功能:输入BCD阳历数据,输出BCD阴历数据(只允许1901-2099年)
调用函数示例:Conversion(c_sun,year_sun,month_sun,day_sun)
如:计算2004年10月16日Conversion(0,0x4,0x10,0x16);
c_sun,year_sun,month_sun,day_sun均为BCD数据,c_sun为世纪标志位,c_sun=0为21世
0x09,0x2e,0x4B, //1937
0x7C,0x96,0xBf, //1938
0x0C,0x95,0x53, //1939
0x0d,0x4A,0x48, //1940
0x6d,0xA5,0x3B, //1941
0x0B,0x55,0x4f, //1942
0x05,0x6A,0x45, //1943
0x7d,0x4A,0xBd, //2063
0x0d,0x4A,0x51, //2064
0x0d,0xA5,0x45, //2065
0x55,0xAA,0xBA, //2066
0x05,0x6A,0x4e, //2067
0x0A,0x6d,0x43, //2068
0x45,0x2e,0xB7, //2069
0x24,0xAe,0xB6, //1909

c语言公历转农历算法

c语言公历转农历算法

c语言公历转农历算法
公历和农历是两种不同的历法系统,公历是以太阳运行为基础的历法,而农历则是以月亮运行为基础的历法。

在一些特殊的场合,我们
可能需要将公历日期转换为农历日期,这就需要用到C语言编写的公
历转农历算法。

公历转农历的算法可以分为两个步骤:首先是计算公历日期到农历
起始点(即农历1900年1月31日)的天数差,然后根据这个天数差计算出对应的农历日期。

首先,我们需要定义一个结构体来表示农历日期,包括年、月、日
和是否闰月等信息。

然后,我们可以编写一个函数来计算公历日期到
农历起始点的天数差。

这个函数可以使用公历日期的年、月、日作为
参数,然后通过一系列的计算来得到天数差。

接下来,我们可以编写另一个函数来根据天数差计算出对应的农历
日期。

这个函数可以使用一个数组来存储每个农历年的天数,然后根
据天数差逐步减去每个农历年的天数,直到找到对应的农历年份。

然后,再根据剩余的天数计算出对应的农历月份和日期。

最后,我们可以在主函数中调用这两个函数来完成公历日期到农历
日期的转换。

我们可以输入一个公历日期,然后调用第一个函数计算
出天数差,再调用第二个函数计算出对应的农历日期,并将结果输出。

需要注意的是,由于农历的特殊性,每个农历年的天数和月份都是不固定的,而且还有闰月的情况。

因此,在编写算法时需要考虑到这些特殊情况,并进行相应的处理。

总之,C语言公历转农历算法是一个比较复杂的问题,需要考虑到公历和农历的差异以及农历的特殊性。

通过合理的算法设计和编程实现,我们可以实现公历日期到农历日期的转换,从而满足一些特殊场合的需求。

C#转换农历的简单方法

C#转换农历的简单方法

C#转换农历的简单方法AD:C#转换农历原来还准备自己写算法,并研究农历规则。

发现那太难和麻烦了,光是农历的推算那就我等专门研究历法的人一下搞懂的。

后来发现.NET类库也提供一些基础的农历类System.Globalization.ChineseLunisolarCalendar。

改装了一下如DateTime时间形式,实现了公历农历转换的功能,但是只能算到1900~2100年之间的。

基本够日常使用了。

C#转换农历代码如下:1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Text;45namespaceSystem6...{7/**////<summary>8///中国常用农历日期时间类9///zj53hao@/zj53hao10///</summary>11classChinaDateTime12...{13privateintyear,month,dayOfMonth;14privateboolisLeap;15publicDateTimetime;1617/**////<summary>18///获取当前日期的农历年19///</summary>20publicintYear21...{22get...{returnyear;}23}2425/**////<summary>26///获取当前日期的农历月份27///</summary>28publicintMonth29...{30get...{returnmonth;}31}3233/**////<summary>34///获取当前日期的农历月中天数35///</summary>36publicintDayOfMonth37...{38get...{returndayOfMonth;}39}4041/**////<summary>42///获取当前日期是否为闰月中的日期43///</summary>44publicboolIsLeap45...{46get...{returnisLeap;}47}4849System.Globalization.ChineseLunisolarCalendarcc;50/**////<summary>51///返回指定公历日期的阴历时间52///</summary>53///<paramname paramname="time"></param>54publicChinaDateTime(DateTimetime)55...{56cc=newSystem.Globalization.ChineseLunisolarCalendar();5758if(time>cc.MaxSupportedDateTime||time<cc.MinSupportedDateTime) 59thrownewException("参数日期时间不在支持的范围内,支持范围:"+cc.MinSupportedDateTime.ToShortDateString()+"到"+cc.MaxSupportedDateTime.ToShortDateString());60year=cc.GetYear(time);61month=cc.GetMonth(time);62dayOfMonth=cc.GetDayOfMonth(time);63isLeap=cc.IsLeapMonth(year,month);64if(isLeap)month-=1;65this.time=time;6667}。

公历和农历之间如何转换3

公历和农历之间如何转换3
daList(1936) = "100100110111030124"
daList(1937) = "100100101110000211"
daList(1938) = "110010010110170131"
daList(1939) = "110010010101000219"
daList(2004) = "010110101010120122"
daList(2005) = "010101101010000209"
daList(2006) = "101010101101170129"
daList(2007) = "001001011101000218"
daList(1956) = "010100101011000212"
daList(1957) = "101010010101080131"
daList(1958) = "111010010101000218"
daList(1959) = "011010101010000208"
daList(1960) = "101011010101060128"
daList(1961) = "101010110101000215"
daList(1962) = "010010110110000205"
daList(1963) = "101001010111040125"
daList(1980) = "100101011011000216"

公历转农历及星期

公历转农历及星期
/*Tim[10]为周数据/Tim[7]/Tim[8]/Tim[9]为农历数据,根据需要自行更换*/
//2010-09-23程序通过测试
/*==================================================*/
#include <intrins.h>
#define uchar unsigned char
0x69,0x6d,0x3C,0x09,0x5B,0x50,0x04,0x9B,0x45, // 1979-1981
0x4A,0x4B,0xB9,0x0A,0x4B,0x4d,0xAB,0x25,0xC2, // 1982-1984
0x06,0xA5,0x54,0x06,0xd4,0x49,0x6A,0xdA,0x3d, // 1985-1987
0x09,0x37,0x4B,0x84,0x97,0xC1,0x04,0x97,0x53, // 2051-2053
0x06,0x4B,0x48,0x66,0xA5,0x3C,0x0e,0xA5,0x4f, // 2054-2056
0x06,0xB2,0x44,0x4A,0xB6,0x38,0x0A,0xAe,0x4C, // 2057-2059
/*公历年对应的农历数据,每年三字节, 格式: *///0x0A,0x95,0x4e,
/*第一字节BIT7-4 位表示闰月月份,值为0 为无闰月, */
/*BIT3-0 对应农历第1-4 月的大小 */
/*第二字节BIT7-0 对应农历第5-12 月大小, */
/*第三字节BIT7 表示农历第13个月大小月份对应的位 */
uint code day_code2[3]={0x111,0x130,0x14e};

公历转换为农历的算法

公历转换为农历的算法

公历转换为农历的算法:0101000101111 前12为代表大小月,第13位代表闰月的大小月6 代表闰月的月份 0 代表无闰月64311 代表当年春节的公历日期1.首先获取当前日期。

S time=+$h2.判断查询日期是否在春节之前。

如果是取上一年的信息。

否则取当前年的信息为农历年3.4.判断当前日期和最近的春节相差的天数。

Days5.如果没有闰月,判断前12位的大小月,如果是大月 ,则相差天数-30 如果是小月则相差天数-29,直到相差天数在30 或者 29天内。

取当前的月份,即农历的月份,天数+1 即为农历的天。

如果有闰月,判断前13位的大小月,判断方法和前面的类似,只是到闰月的月份时,需要在前面增加一个闰字。

/// gl 23/06/2016格式 gldays数字形式的日期/// w ##class(websys.CalendarUtil).ToLuner("01/01/2017")/// @param: gl 公历日期格式 DD/MM/YYYY/// @return: 返回农历日期 2016*8*12 2017*闰6*12,2017*闰6*12 ClassMethod ToLuner(gl = {+$h}){//q "2016*8*12"s Nmonth=""s Nday=""s ^TMP("Toluner")=$g(gl)if gl=""{set gldt=$hset gldays=$p(gldt,",",1)set gl=$zd(gldays,4)}else{set gldays=$zdh(gl,4)};获取传过来的年份set year=$p(gl,"/",3);查询数据库,获取这个年份的信息串set calId=""Set calId = $o(^websys.CalendarUtilI("YearIndex"," "_year,calId))q:calId="" ""s g=$list(^websys.CalendarUtilD(calId),1,3)Set calInfo = $list(g,2)b;获取这个信息串的春节s springFes=$p(calInfo,"^",3);如果要查询的日期在春节之前,获取前一年的信息串if (gldays<springFes){s year=(year-1);获取前一年信息串,取得春节set calId=""Set calId = $o(^websys.CalendarUtilI("YearIndex"," "_year,calId)) set g=$list(^websys.CalendarUtilD(calId),1,3)Set calInfo = $list(g,2)set springFes=$p(calInfo,"^",3)}set Nyear=yearset days=gldays-springFesset lmon=$p(calInfo,"^",2)set daystr=$p(calInfo,"^",1)b ;if (lmon=0){;无闰月for i=1:1:12{if ($e(daystr,i)=1){;大月 30天if (days<30){s Nmonth=is Nday=days+1q}else{s days=days-30}}else{;小月 29天if (days<29){s Nmonth=is Nday=days+1q}else{s days=days-29}}}}else{for i=1:1:13 {if (i'>lmon){if ($e(daystr,i)=1){;大月 30天if (days<30){s Nmonth=is Nday=days+1q}else{s days=days-30}}else{;小月 29天if (days<29){s Nmonth=is Nday=days+1q}else{s days=days-29}}} elseif (+i=+(lmon+1)){if ($e(daystr,13)=1){;大月 30天if (days<30){s Nmonth="闰"_lmons Nday=days+1q}else{s days=days-30}}else{;小月 29天if (days<29){s Nmonth="闰"_lmons Nday=days+1q}else{s days=days-29}}}else{if ($e(daystr,(i-1))=1){;大月 30天if (days<30){s Nmonth=(i-1)s Nday=days+1q}else{s days=days-30}}else{;小月 29天if (days<29){s Nmonth=(i-1)s Nday=days+1q}else{s days=days-29}}}}}Quit Nyear_"*"_Nmonth_"*"_Nday}。

公历日期与农历日期的相互转换程序

公历日期与农历日期的相互转换程序

公历日期与农历日期的相互转换程序//**********************************// 公历日期与农历日期的相互转换程序// 公元1800年1月25日~2101年1月28日// 请在VC++6.0平台运行//**********************************#include;#include;#include;#include;#include;#include;struct date{ short year,month,day; }d1={ 1800,1,25 },//农历1800正月初一(星期六)d2={ 2101,1,28 };//农历2100腊月廿九(未使用) struct lunarYear //农历年{ char run;//闰月月份(0表示无闰月)char ZL[13];//农历i月初一对应公历i月ZL[i]日(广义)} Year[2101//但是ZL[i]的最高位1表示大月0表示小月-1800]={4};//农历1800年闰四月#define leap(y) !(y%(y%100?4:400)) //公元闰年宏定义unsigned chardays[]={ 0,31,28,31,30,31,30,31,31,30,31,30,31 }, b[]= //农历1800-2100年大月(30天)小月(29天)闰月数据(hex string){&quot;adca5aa92bb525bba25bb493b64a5ba9add496ea8a6 ed14eea4a6da5b6&quot;&quot;545baa4bba45bba82b75a5b654abaa55d526eda4aed 495da526daa5655&quot;&quot;abb295ba5257aa4b75a95655abaa56ea4a5da92ed96 5d594adaa56692b&quot;&quot;75a5ba64977493b6ca5a69add496da925dd24dda495 da9add45a6a4b75&quot;&quot;4937692775a5b6545baa2dd526dda49dd495ba525ba a5555ab6a937652&quot;&quot;57ea4a75a95655abaa55da4a5da92bd925db54abaa5 6592b75a5ae6497&quot;&quot;ec92aed25659abb495da925dd24bba495ba9add4566 a4b75492fe9266d&quot;&quot;a5aed4566a2db525bba49bb493ba525baa55d5aa6a9 36ed24eea4a6da9&quot;&quot;36d5aaaa55b64a5ba92b75a5ba54abaa55d52a6da5a ed495ec926daa56&quot;&quot;55abb495ba525bb24b76495769abb455da4a6dc92ee 925dda4add4566a&quot;&quot;4bb5a5baa4977493b652576a4db5a6da926dd24dda4 a5da92dd5aa6a55&quot;&quot;b54937692775a5b654abaa55d52a5da5add495ba925 daa55d5aa6c95b6&quot;&quot;5257724b76c95659abac55da4a5da92dd925bda4abb 4555a4b6da5b6649&quot;&quot;7f492aed2566a4bb5a5da925dd24bba495ba92bb5aa 6a53754937e9266d&quot;&quot;a5aed4966a55b52a5ba5abb495ba525baa55d5aa6a9 5aed256ea4a6ec94&quot;&quot;ed9aa6a55b64a5ba92bb945bb64abb455d64a6da5ae e416eda26ed25502&quot;};short rs[22]={ //农历1800-2100年111个闰月所形成的110个间距的数据32198,25072,32079,29168,31350,3554,29118,28494,25 464,28215,7608,27766,3975,30902,28494,21489,28214,7132,27766,397 5,25078,28039};char f(short m,short x)//1月x日相当于m月f日{for(short i=1;i;>;=3;Year[(ir-r)/12].run=(ir-r)%12;}lunarYear*p=&Year[0];r=p->;run;for(t=0,i=0;b[i]!='\0';i+=2,t++)//hex string#define VAL(h)(h;12+!!r){ M=1;hao-=365+leap(y);y++;r=(++p)->;ru n; }t=b[i/8];t>;>;=i%8; days[2]=28+leap(y);if(r==0||M;ZL[M]=f(M,hao);if(t%2)p->;ZL[M]|=0x80;}elseif(M>;1+r){p->;ZL[M-1]=f(M-1,hao);if(t%2)p->;ZL[M-1]|=0x80;}else{p->;ZL[0]=f(r,hao);if(t%2)p->;ZL[0]|=0x80;}hao+=29+t%2;}}date getSolar(date D)//农历&rarr;公历{short im,m;im=m=D.month;if(im;ZL[im])-1+D.day;days[2]=28+leap(d.year);while(d.day>;days[m]){ d.day-=days[m];m=m%12+1;if(m==1)d.year++; }d.month=m;return d;}date getLunar(date d)//公历&rarr;农历{lunarYear*p=&Year[d.year-1800];days[2]=28+leap(d.year);short m=d.month;d.day-=(p->;ZL[m]&0x7f)-1;while(d.day;run;else if(m==1){ m=12;d.year--;p--; }else if(p->;run==m-1)m=0;else m--;d.day+=29+(p->;ZL[m];run;d.month=m;return d;}long total(date a)//公元以来的天数{days[2]=28+leap(a.year);long C,m,x=a.year-1; for(C=a.day,m=1;m;2100)ok=-1;else if(m;12)ok=0;else{days[2]=28+leap(y);if(t;days[m])ok=0;}if(total(d);2100)return -1;if(T;30)return 0;//排除明显的非法&quot;日&quot;号if(M==0||M>;12)return 0;//排除明显的非法&quot;月&quot;号lunarYear* p=&Year[Y-1800];if((M;run?29+(p->;ZL[0];ZL[M];ZL[i];'4');if(cho=='4'){gotoxy(10,23);cout;'9')break;Y=Y*10+(tmp-'0');}}if(Y;2100)Y=2008;}system(&quot;cls&quot;);if(cho;>;dt.year>;>;c>;>;dt.month>;>;c>;>;dt.day; //c为分隔符o=ok(dt);if(o==-1)gotoMenu; }while(o;>;DT.year>;>;c>;>;DT.month>;>;c>;>;DT.day;//c为分隔符o=OK(DT);if(o==-1)gotoMenu; }while(o;1?xq[m]:&quot;正&quot;);run!=m)continue;cout<<&quot;闰&quot;<<xq[m]<<&quot;月&quot;<<(BIG(0)?&quot;大&quot;:&quot;小&quot;)<<&quot;&quot;;if(++counter%4==0)cout<<&quot;\n\n&quot;;}getch();goto Menu;}else if(cho=='0')system(&quot;cls&quot;); return 0;}。

C语言农历表算法

C语言农历表算法

#include<stdio.h>void DateTrans(char *chDate,int *nYear,int *nMonth,int *nDay);// 1int IsLeapYear(int nYear);// 2int GetWeekOfFirstday(int nYear);// 3int GetWeek(int nYear,int nMonth,int nDay,int nWeekOfFirstday);// 4void PrintCalendar(int nWeek,int nDay,int nMonthDays,char *chDate);// 5void DateTrans(char *chDate,int *nYear,int *nMonth,int *nDay)// 1{*nYear=(chDate[0]-'0')*1000+(chDate[1]-'0')*100+(chDate[2]-'0')*10+chDate[3] -'0';*nMonth=(chDate[5]-'0')*10+chDate[6]-'0';*nDay=(chDate[8]-'0')*10+chDate[9]-'0';}int IsLeapYear(int nYear)// 2{if(nYear%4==0)return 1;elsereturn 0;}int GetWeekOfFirstday(int nYear)// 3{if(nYear>2000)return ((nYear-2001)*365+(nYear-2001)/4+1)%7;else if(nYear<2000)return 6-((2000-nYear)*365+(2000-nYear)/4)%7;elsereturn 6;}int GetWeek(int nYear,int nMonth,int nDay,int nWeekOfFirstday)// 4{int nDaysYear[]={31,28,31,30,31,30,31,31,30,31,30,31};int nDaysLeapYear[]={31,29,31,30,31,30,31,31,30,31,30,31};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];}return (sum+nDay+nWeekOfFirstday-1)%7;}}void PrintCalendar(int nWeek,int nDay,int nMonthDays,char *chDate) // 5{int i,j;printf("the calender of this month as following:\n");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(){char chDate[11],i=0,j,isleapyear;int nYear,nMonth,nDay;int nWeekOfFirstday;int nMonthDays;int nWeek;char *Week;int nDaysYear[]={31,28,31,30,31,30,31,31,30,31,30,31};int nDaysLeapYear[]={31,29,31,30,31,30,31,31,30,31,30,31};printf("请输入你要查找的日期,如(2001\\01\\01或2001.01.01:\n或者是你想要日历的月份:如(2000\\01或2000.01):\n");do{scanf("%c",&chDate[i]);i++;}while(chDate[i-1]!='\n');if(i==11)chDate[i-1]='\0';elsefor(j=8;j<11;j++)chDate[j]='0';DateTrans(chDate,&nYear,&nMonth,&nDay);// 1while(nYear<=0||nMonth<1||nMonth>12){printf("查询年月chDate非法\n");return 0;}nWeekOfFirstday = GetWeekOfFirstday(nYear);// 3nWeek=GetWeek(nYear,nMonth,nDay,nWeekOfFirstday);// 4isleapyear=IsLeapYear(nYear);// 2if(isleapyear==1)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;}switch(nWeek){case 0:Week="SUNDAY";break;case 1:Week="MONDAY";break;case 2:Week="TUESDAY";break;case 3:Week="WEDNESDAY";break;case 4:Week="THUESDAY";break;case 5:Week="FRIDAY";break;case 6:Week="SATERDAY";break;}printf("This day (%s) is %s\n",chDate,Week);printf("OK!\n");}elsePrintCalendar(nWeek,nDay,nMonthDays,chDate); //5 }。

c++万年历及公历农历转换源代码2

c++万年历及公历农历转换源代码2

#include <stdio.h>#include <stdlib.h>#include <conio.h>#define X " Sun Mon Tue Wed Thu Fri Sat"#define P printf#define B break#define FP fprintfstruct date /*日期*/{int year;int month;int date;};struct taglunarcal /**/{int basedays;int intercalation;int monthdays[13];}dalist[]={{31,8,0,1,0,0,1,0,1,1,0,1,1,0,1},{50,0,0,1,0,0,1,0,1,0,1,1,1,0,0},{39,0,1,0,1,0,0,1,0,1,0,1 ,1,1,0},{29,5,0,1,0,1,0,0,1,0,0,1,1,0,1},{47,0,1,1,0,1,0,0,1,0,0,1,1,0,0},{35,0,1,1,0,1,1,0,0,1,0,1,0,1,0},{25,4,0,1,1,0,1,0,1,0,1,0,1,0,1},{4 4,0,0,1,0,1,0,1,1,0,1,0,1,0,0},{33,0,1,0,0,1,1,0,1,0,1,1,0,1,0},{22,2,0,1,0,0,1,0,1,0,1,1,1,0,1},{41,0,0,1,0,0,1,0,1,0,1,1,1,0,0},{3 0,6,1,0,1,0,0,1,0,0,1,1,0,1,1},{49,0,1,0,1,0,0,1,0,0,1,1,0,1,0},{37,0,1,1,0,1,0,0,1,0,0,1,0,1,0},{26,5,1,1,0,1,0,1,0,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,1,1,0,1,0,1,0,1,0,1,0,0},{37,0,1,0,1,0,1,1,0,1,0,1,0,1,0},{26,5,0,1,0,0,1,0,1,1,0,1,0,1,1},{45,0,0,1,0,0,1,0,1,1,0,1,1,0,0},{3 4,0,1,0,1,0,0,1,0,1,0,1,1,1,0},{24,4,0,1,0,1,0,1,0,0,1,1,1,0,1},{41,0,1,1,0,1,0,0,1,0,0,1,1,0,0},{30,8,1,1,1,0,1,0,0,1,0,1,1,0,1},{4 9,0,1,1,0,1,0,1,0,1,0,0,1,0,0},{38,0,1,1,0,1,1,0,1,0,1,0,1,0,0},{27,6,0,1,1,0,1,0,1,0,1,0,1,0,0},{46,0,0,1,0,1,0,1,1,0,1,1,0,1,0},{3 6,0,0,1,0,0,1,0,1,0,1,1,1,0,0},{25,4,1,0,1,0,1,0,0,1,1,1,0,1,0},{43,0,1,0,1,0,0,1,0,0,1,1,0,1,0},{32,0,1,0,1,0,0,0,0,1,0,1,0,1,0},{2 1,2,1,1,1,1,0,0,1,0,0,1,0,1,1},{40,0,1,1,0,1,0,1,0,1,0,0,1,0,0}};getleap( int year ) /*1代表闰年*/{if ( year % 400 == 0 )return 1;else if ( year % 100 == 0 )return 0;else if ( year % 4 == 0 )return 1;elsereturn 0;}print(int n){int i;for(i=0;i<n;i++) printf(" ");}int day(int year){long a,b;if(year<=2000){a=2000-year;b=6-(a+a/4-a/100+a/400)%7; return b;}else{a=year-2000; b=(a+1+(a-1)/4-(a-1)/100+(a-1)/400)%7+6; return b%7; }}solardate(struct date * input) /*公历年第几天*/{int i,number=0,solarcal[12]={31,28,31,30,31,30,31,31,30,31,30,31}; number=getleap(input->year);for(i=0;i<input->month-1;i++){number+=solarcal[i];}return number+input->date;}lunardate(struct date *input)/*农历年第几天*/{int i,leap=0,number=0;if(dalist[input->year-1900].intercalation==0)leap=0;else if(input->month==dalist[input->year-1900].intercalation){printf(" 0 not leap month\n 1 leap month");scanf("%d",&leap);}else if(input->month>dalist[input->year-1900].intercalation) leap=1;for(i=0;i<input->month+leap-1;i++)number+=dalist[input->year-1900].monthdays[i]+29;return number+input->date;}lunarmonth(int year,int *mon){int i,j;mon[0]=dalist[year].monthdays[0]+29;for(i=1,j=1;i<12;i++,j++){if(i==dalist[year].intercalation){mon[i-1]+=dalist[year].monthdays[j]+29;j++;}mon[i]=mon[i-1]+dalist[year].monthdays[j]+29;}}main(){int i,j,k,m,n,f1,f2,year,d,y,ly,cord,greday,lunday,diff,add,leap,tlylm[12],lastylm[12],a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},SolarDays[2][12] = {{31,59,90,120,151,181,212,243,273,304,334,365},{31,60,91,121,152,182,213,244,274,305,335, 366}};char fname[12]={"0"}; FILE *fw;struct date input;do{printf("\n--------------------------------------------\n");printf(" 请选择");printf("\n--------------------------------------------\n");printf(" 1 公历转换成农历");printf("\n--------------------------------------------\n");printf(" 2 农历转换成公历");printf("\n--------------------------------------------\n");printf(" 3 万年历");printf("\n--------------------------------------------\n");printf(" 4 退出");printf("\n--------------------------------------------\n");printf("\n 请选择: 1,2,3,4\n");scanf("%d",&cord);clrscr();switch(cord){case 1:{printf("\n(公历) 请输入年.月.日(yyyy.mm.dd) \n");scanf("%d.%d.%d",&input.year,&input.month,&input.date);/*输入年月日*/y=input.year;greday=solardate(&input);/*公历年第几天*/diff=greday-dalist[y-1900].basedays;if(diff>0)lunarmonth(y-1900,tlylm);else{y-=1;lunarmonth(y-1900,tlylm);diff+=tlylm[11];}for(i=0;tlylm[i]<diff;i++);if(i!=0)diff-=tlylm[i-1];printf("(农历) %d.%d.%d",y,i+1,diff);break;}clrscr();case 2:{printf("\n(农历) 请输入年.月.日(yyyy.mm.dd) \n");scanf("%d.%d.%d",&input.year,&input.month,&input.date);y=input.year;ly=getleap(y);lunday=lunardate(&input);/*农历年第几天*/add=lunday+dalist[y-1900].basedays;if(add-365+ly>0){add-=365+ly;y+=1;}for(i=0;SolarDays[ly][i]<add;i++);if(i!=0)add-=SolarDays[ly][i-1];printf("(公历) %d.%d.%d",y,i+1,add);break;}case 3:{system("cls");P(" 请输入你所要查看的年份:");scanf("%d",&year);fw=fopen(fname,"w+");if(fw==NULL){P(" can not open file."); return;}P(" The calendar of the year %d.\n",year);FP(fw,"The calendar of the year %d.\n",year);d=day(year);if(year%4==0&&year%100||year%400==0) a[2]++;for(i=1;i<=12;i+=2){m=0; n=0; f1=0; f2=0;switch(i){case 1:P(" Januray 1 "); FP(fw," Januray 1 "); B; case 3:P(" March 3 "); FP(fw," March 3 "); B; case 5:P(" May 5 "); FP(fw," May 5 "); B; case 7:P(" July 7 "); FP(fw," July 7 "); B; case 9:P(" September 9 "); FP(fw," September 9 "); B; case 11:P(" Nevember 11 "); FP(fw," Nevember 11 "); B; }print(21);for(k=0;k<21;k++) fprintf(fw," ");switch(i+1){case 2:P(" February 2 "); FP(fw," February 2 ");B; case 4:P(" April 4 "); FP(fw," April 4 ");B;case 6:P(" June 6 "); FP(fw," June 6 ");B; case 8:P(" August 8 "); FP(fw," August 8 "); B; case 10:P(" October 10 "); FP(fw," October 10 ");B; case 12:P(" December 12"); FP(fw," December 12");B;}P("\n");fprintf(fw,"\n");P(X); fprintf(fw,X); print(6);fprintf(fw," "); P(X); fprintf(fw,X);fprintf(fw,"\n"); P("\n");for(j=0;j<6;j++){if(j==0){print(d*4); for(k=0;k<d*4;k++) fprintf(fw," ");for(k=0;k<7-d;k++){P("%4d",++m); fprintf(fw,"%4d",m);}print(6); fprintf(fw," ");d+=a[i]%7; d%=7;print(d*4); for(k=0;k<d*4;k++) fprintf(fw," ");for(k=0;k<7-d;k++){P("%4d",++n); fprintf(fw,"%4d",n);}P("\n"); fprintf(fw,"\n");}else{for(k=0;k<7;k++){if(m<a[i]){P("%4d",++m); fprintf(fw,"%4d",m);}else{print(4); fprintf(fw,"");}if(m==a[i]) f1=1;}print(6); fprintf(fw," ");for(k=0;k<7;k++){if(n<a[i+1]){P("%4d",++n);fprintf(fw,"%4d",n);}else{print(4); fprintf(fw,"");}if(n==a[i+1]) f2=1;}P("\n"); fprintf(fw,"\n");if(f1&&f2) B;}}d+=a[i+1]%7; d%=7; P(" "); fprintf(fw," "); if(i==5){getch();system("cls");}}fclose(fw);getch();break;}case 4:{exit(0);}}}while(cord<=4);}。

公历转换成农历c语言函数

公历转换成农历c语言函数

公历转换成农历c语言函数在编程过程中,经常需要进行日期的转换操作。

其中,将公历转换成农历是一个常见的需求。

在C语言中,我们可以通过编写一个函数来实现这个功能。

下面是一个实现公历转换成农历的C语言函数的示例:```c#include <stdio.h>typedef struct {int year; // 公历年份int month; // 公历月份int day; // 公历日期} Date;typedef struct {int year; // 农历年份int month; // 农历月份int day; // 农历日期} LunarDate;// 公历转农历函数void convertToLunar(const Date* gregorianDate, LunarDate* lunarDate) {// 在这里编写公历转农历的具体实现代码// 具体实现略}int main() {Date gregorianDate = {2022, 10, 1}; // 示例:公历日期为2022年10月1日LunarDate lunarDate;convertToLunar(&gregorianDate, &lunarDate);printf("公历日期:%d年%d月%d日\n", gregorianDate.year, gregorianDate.month, gregorianDate.day);printf("农历日期:%d年%d月%d日\n", lunarDate.year, lunarDate.month, lunarDate.day);return 0;}```在上述代码中,我们首先定义了`Date`和`LunarDate`结构体,分别表示公历日期和农历日期。

`Date`结构体包含了年、月、日三个字段,而`LunarDate`结构体也包含了年、月、日三个字段。

关于阳历转换为阴历和星期的单片机函数

关于阳历转换为阴历和星期的单片机函数

关于阳历转换为阴历和星期的单片机函数From:hells参加比赛培训的时候老师让做基于DS1302的日历,但是大家都知道DS1302只能显示阳历的日期而不能显示阴历,还有一个致命的弱点就是星期和日期不同步,还需要自己写算法计算,下面是我在网上找的一些资源,在改动一些代码之后用在单片机上的,用的时候直接拿过来用就可以。

以后会整理一下其他的算法上传(本次是基于查表法的)#include"nongli.h" //包含的头文件,主要包含一些声明定义int code monthTotal[13] = {0,31,59,90,120,151,181,212,243,273,304,334,365};int NM=0,ND=0;//数据unsigned char code week_code[12]={0,3,3,6,1,4,6,2,5,0,3,5};unsigned long code lunar200y[199] = {0x04AE53,0x0A5748,0x5526BD,0x0D2650,0x0D9544,0x46AAB9,0x056A4D,0x09AD42,0x24AEB6,0x04AE4A,/*1901-1910*/0x6A4DBE,0x0A4D52,0x0D2546,0x5D52BA,0x0B544E,0x0D6A43,0x296D37,0x095B4B,0x749BC1,0x049754,/*1911-1920*/0x0A4B48,0x5B25BC,0x06A550,0x06D445,0x4ADAB8,0x02B64D,0x095742,0x2497B7,0x04974A,0x664B3E,/*1921-1930*/0x0D4A51,0x0EA546,0x56D4BA,0x05AD4E,0x02B644,0x393738,0x092E4B,0x7C96BF,0x0C9553,0x0D4A48,/*1931-1940*/0x6DA53B,0x0B554F,0x056A45,0x4AADB9,0x025D4D,0x092D42,0x2C95B6,0x0A954A,0x7B4ABD,0x06CA51,/*1941-1950*/0x0B5546,0x555ABB,0x04DA4E,0x0A5B43,0x352BB8,0x052B4C,0x8A953F,0x0E9552,0x06AA48,0x6AD53C,/*1951-1960*/0x0AB54F,0x04B645,0x4A5739,0x0A574D,0x052642,0x3E9335,0x0D9549,0x75AABE,0x056A51,0x096D46,/*1961-1970*/0x54AEBB,0x04AD4F,0x0A4D43,0x4D26B7,0x0D254B,0x8D52BF,0x0B5452,0x0B6A47,0x696D3C,0x095B50,/*1971-1980*/0x049B45,0x4A4BB9,0x0A4B4D,0xAB25C2,0x06A554,0x06D449,0x6ADA3D,0x0AB651,0x093746,0x5497BB,/*1981-1990*/0x04974F,0x064B44,0x36A537,0x0EA54A,0x86B2BF,0x05AC53,0x0AB647,0x5936BC,0x092E50,0x0C9645,/*1991-2000*/0x4D4AB8,0x0D4A4C,0x0DA541,0x25AAB6,0x056A49,0x7AADBD,0x025D52,0x092D47,0x5C95BA,0x0A954E,/*2001-2010*/0x0B4A43,0x4B5537,0x0AD54A,0x955ABF,0x04BA53,0x0A5B48,0x652BBC,0x052B50,0x0A9345,0x474AB9,/*2011-2020*/0x06AA4C,0x0AD541,0x24DAB6,0x04B64A,0x69573D,0x0A4E51,0x0D2646,0x5E933A,0x0D534D,0x05AA43,/*2021-2030*/0x36B537,0x096D4B,0xB4AEBF,0x04AD53,0x0A4D48,0x6D25BC,0x0D254F,0x0D5244,0x5DAA38,0x0B5A4C,/*2031-2040*/0x056D41,0x24ADB6,0x049B4A,0x7A4BBE,0x0A4B51,0x0AA546,0x5B52BA,0x06D24E, 0x0ADA42,0x355B37,/*2041-2050*/0x09374B,0x8497C1,0x049753,0x064B48,0x66A53C,0x0EA54F,0x06B244,0x4AB638, 0x0AAE4C,0x092E42,/*2051-2060*/0x3C9735,0x0C9649,0x7D4ABD,0x0D4A51,0x0DA545,0x55AABA,0x056A4E,0x0A6D43, 0x452EB7,0x052D4B,/*2061-2070*/0x8A95BF,0x0A9553,0x0B4A47,0x6B553B,0x0AD54F,0x055A45,0x4A5D38,0x0A5B4C, 0x052B42,0x3A93B6,/*2071-2080*/0x069349,0x7729BD,0x06AA51,0x0AD546,0x54DABA,0x04B64E,0x0A5743,0x452738, 0x0D264A,0x8E933E,/*2081-2090*/0x0D5252,0x0DAA47,0x66B53B,0x056D4F,0x04AE45,0x4A4EB9,0x0A4D4C,0x0D1541, 0x2D92B5 /*2091-2099*/};//转换成农历的函数,再用的时候直接在main函数里面调用本函数即可void toLunar(int year,int month,int day){long bySpring,bySolar,daysPerMonth;int index,flag;//bySpring 记录春节离当年元旦的天数。

阳历到阴历的转换

阳历到阴历的转换

阳历到阴历的转换/*西历农历转换程式prototype: int CalConv( struct ConvDate * );struct ConvDate{int Source; ==0 则输入日期为西历, !=0 则输入为农历int SolarYear; 输出或输入之西历年份int SolarMonth; 西历月int SolarDate; 西历日int LunarYear; 输出或输入之农历年份int LunarMonth; 农历月int LunarDate; 农历日int Weekday; 该日为星期几 ( 0==星期日, 1==星期一, ... )int Kan; 该日天干 ( 0==甲, 1==乙, ..., 9==癸 )int Chih; 该日地支 ( 0==子, 1==丑, ..., 11==亥 )};呼叫时须设定 Souce 的值, 若为 0 则为西历转农历, 否则为农历转西历. 然後视输入为西历或农历来设定西历或农历的年月日. 转换後的年月日会填入结构中( 农历或西历 ), 以及该日为星期几, 天干地支.若函式的返回值为 0 表示没有错误, 1 为输入之年份错误, 2 为输入之月份错误,3 为输入之日期错误.输入之西历年须在 1937 - 2031 间输入之农历年须在 1936 - 2030 间若须扩充, 则增加 LunarCal[]*/#define FIRSTYEAR 1936 /* The first year in LunarCal[] */struct ConvDate{int Source;int SolarYear;int SolarMonth;int SolarDate;int LunarYear;int LunarMonth;int LunarDate;int Weekday;int Kan;int Chih;};struct tagLunarCal{int BaseDays; /* 到西历 1 月 1 日到农历正月初一的累积日数 */int Intercalation; /* 闰月月份. 0==此年没有闰月 */int BaseWeekday; /* 此年西历 1 月 1 日为星期几再减 1 */int BaseKanChih; /* 此年西历 1 月 1 日之干支序号减 1 */int MonthDays[13]; /* 此农历年每月之大小, 0==小月(29日), 1==大月(30日) */ };struct tagLunarCal LunarCal[] = {{ 23, 3, 2, 17, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0 }, /* 1936 */{ 41, 0, 4, 23, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1 },{ 30, 7, 5, 28, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1 },{ 49, 0, 6, 33, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 },{ 38, 0, 0, 38, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 }, /* 1940 */{ 26, 6, 2, 44, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0 },{ 45, 0, 3, 49, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },{ 35, 0, 4, 54, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1 },{ 24, 4, 5, 59, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1 }, /* 1944 */{ 43, 0, 0, 5, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1 },{ 32, 0, 1, 10, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 },{ 21, 2, 2, 15, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 },{ 40, 0, 3, 20, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 }, /* 1948 */。

C语言公历转农历写法

C语言公历转农历写法
"初六","初七","初八","初九","初十", "十一","十二","十三","十四","十五", "十六","十七","十八","十九","二十", "廿一","廿二","廿三","廿四","廿五", "廿六","廿七","廿八","廿九","三十"};
/*农历月份名*/ const char *cMonName[] = {"*","正","二","三","四","五","六",
"未","申","酉","戌","亥"}; /*属相名称*/ const char *cShuXiang[] = {"鼠","牛","虎","兔","龙","蛇",
"马","羊","猴","鸡","狗","猪"}; /*农历日期名*/ const char *cDayName[] = {"*","初一","初二","初三","初四","初五",

c 农历年月日程序设计

c 农历年月日程序设计

c 农历年月日程序设计C语言是一种广泛应用于计算机科学和软件开发领域的编程语言,其强大的功能和灵活的语法使其成为许多程序员的首选。

在C语言中,我们可以通过编写程序来实现农历年月日的计算和转换。

下面我们就以C语言编写农历年月日程序为例,来介绍一下具体的实现方法。

我们需要了解农历的基本知识。

农历是一种以月亮的运行周期为基础的历法,与阳历有所不同。

农历的年份通常由十二个动物的名称来表示,而月份和日期则采用数字来表示。

农历的计算涉及到一些复杂的算法和规则,但是我们可以利用已有的算法库来简化这一过程。

在C语言中,我们可以使用time.h头文件中的函数来获取当前的日期和时间。

具体的操作步骤如下:1. 引入头文件:首先,我们需要在程序中引入time.h头文件,以便使用其中的日期和时间相关函数。

```c#include <time.h>```2. 获取当前的日期和时间:我们可以使用time函数来获取当前的日期和时间,并将其保存在一个time_t类型的变量中。

```ctime_t t = time(NULL);```3. 将日期和时间转换为本地时间:由于time函数返回的是UTC时间(世界标准时间),我们需要将其转换为本地时间。

可以使用localtime函数来实现这一转换。

```cstruct tm *local = localtime(&t);```4. 获取年月日信息:通过local结构体中的成员变量,我们可以获取当前的年份、月份和日期。

```cint year = local->tm_year + 1900;int month = local->tm_mon + 1;int day = local->tm_mday;```5. 将日期转换为农历日期:最后,我们可以使用算法库或自定义的算法将公历日期转换为农历日期。

这里我们以调用算法库为例。

```c// 假设已经定义了一个函数lunar_calendar,用于将公历日期转换为农历日期int lunar_year, lunar_month, lunar_day;lunar_calendar(year, month, day, &lunar_year, &lunar_month, &lunar_day);```通过以上的步骤,我们就可以在C语言中实现农历年月日的计算和转换了。

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

if (k == 12) { if (wCurMonth == wNongliData[m] / 65536 + 1)
wCurMonth = 1 - wCurMonth; else if (wCurMonth > wNongliData[m] / 65536 + 1) wCurMonth = wCurMonth - 1; } /*--生成农历天干、地支、属相 ==> wNongli--*/ wsprintf(szShuXiang,"%s",cShuXiang[((wCurYear - 4) % 60) % 12]); wsprintf(szNongli,"%s(%s%s) 年 ",szShuXiang,cTianGan[((wCurYear - 4) % 60) % 10],cDiZhi[((wCurYear - 4) % 60) % 12]); /*--生成农历月、日 ==> wNongliDay--*/ if (wCurMonth < 1) wsprintf(szNongliDay,"闰%s",cMonName[-1 * wCurMonth]); else strcpy(szNongliDay,cMonName[wCurMonth]); strcat(szNongliDay,"月"); strcat(szNongliDay,cDayName[wCurDay]); return strcat(szNongli,szNongliDay); }
"七","八","九","十","十一","腊"}; /*公历每月前面的天数*/ const int wMonthAdd[12] = {0,31,59,90,120,151,181,212,243,273,304,334}; /*农历数据*/ const int wNongliData[100] = {2635,333387,1701,1748,267701,694,2391,133423,1175,396438
"未","申","酉","戌","亥"}; /*属相名称*/ const char *cShuXiang[] = {"鼠","牛","虎","兔","龙","蛇",
"马","羊","猴","鸡","狗","猪"}; /*农历日期名*/ const char *cDayName[] = {"*","初一","初二","初三","初四","初五",
static int wCurYear,wCurMonth,wCurDay; static int nTheDate,nIsEnd,m,k,n,i,nBit; TCHAR szNongli[30], szNongliDay[10],szShuXiang[10]; /*---取当前公历年、月、日---*/ wCurYear = pSt->wYear; wCurMonth = pSt->wMonth; wCurDay = pSt->wDay; /*---计算到初始时间 1921 年 2 月 8 日的天数:1921-2-8(正月初一)---*/ nTheDate = (wCurYear - 1921) * 365 + (wCurYear - 1921) / 4 + wCurDay + wMonthAdd[wCurMonth - 1] - 38; if((!(wCurYear % 4)) && (wCurMonth > 2)) nTheDate = nTheDate + 1; /*--计算农历天干、地支、月、日---*/ nIsEnd = 0; m = 0; while(nIsEnd != 1) { if(wNongliData[m] < 4095)
"初六","初七","初八","初九","初十", "十一","十二","十三","十四","十五", "十六","十七","十八","十九","二十", "廿一","廿二","廿三","廿四","廿五", "廿六","廿七","廿八","廿九","三十"};
/*农历月份名*/ const char *cMonName[] = {"*","正","二","三","四","五","六",
公历转农历(C 版本)
Tags:版本 wCurMonth wCurYear if 农历 nTheDate nBit const 公历转农历(C 版本) PHP 开发环境的选择、建立及使用[8] 编写自定义任务,轻松扩展 Ant (2) 代联接的自定义右键 菜单面试中如何体现身价希特勒生日(4 月 20 日)突破生命中那条线怎么用 ado 打开带密 码的 access 数据库算法复杂度攻击激烈讨论在 Visual StudBiblioteka 中使用自定义插 公历转农 历(C 版本) 版本 wCurMonth wCurYear if 农历 nTheDate nBit const
,3402,3749,331177,1453,694,201326,2350,465197,3221,3402 ,400202,2901,1386,267611,605,2349,137515,2709,464533,1738 ,2901,330421,1242,2651,199255,1323,529706,3733,1706,398762 ,2741,1206,267438,2647,1318,204070,3477,461653,1386,2413 ,330077,1197,2637,268877,3365,531109,2900,2922,398042,2395 ,1179,267415,2635,661067,1701,1748,398772,2742,2391,330031 ,1175,1611,200010,3749,527717,1452,2742,332397,2350,3222 ,268949,3402,3493,133973,1386,464219,605,2349,334123,2709 ,2890,267946,2773,592565,1210,2651,395863,1323,2707,265877};
前段时间做软件写了个公历转农历的函数,目前公开给大家参考,有兴趣的朋友可以在此 基础上进一步完善其功能 /*------------农历转换函数-----------*/ char *GetDayOf(PSYSTEMTIME pSt) { /*天干名称*/ const char *cTianGan[] = {"甲","乙","丙","丁","戊","己","庚","辛","壬","癸"}; /*地支名称*/ const char *cDiZhi[] = {"子","丑","寅","卯","辰","巳","午",
k = 11; else k = 12; n = k; while(n>=0) { //获取 wNongliData(m)的第 n 个二进制位的值 nBit = wNongliData[m]; for(i=1;i<n+1;i++)
nBit = nBit/2; nBit = nBit % 2; if (nTheDate <= (29 + nBit)) { nIsEnd = 1; break; } nTheDate = nTheDate - 29 - nBit; n = n - 1; } if(nIsEnd) break; m = m + 1; } wCurYear = 1921 + m; wCurMonth = k - n + 1; wCurDay = nTheDate;
相关文档
最新文档