php农历转公历源码_PHP日历代码

hacker|
123

文章目录:

跪求万年历—公历转换器C++代码

我这里特地为你写了个C++的,看看是不是你所要的。代码实现了公历转农历,农历转公历,以下是类的定义(整个工程源代码请看附件):

class CTransform

{

public:

 CTransform(void);

 virtual ~CTransform(void);

private:

 //判断闰年,参数:年份,返回值:false-平年,true-闰年

 bool IsLeapYear(int iYear);

 //计算日期在年内的序数,参数:年,月,日,年内序数,返回值:false-失败,true-成功

 bool GetDaysNumInYear(int iYear, int iMonth, int iDay,int nDays);

 //从年内序数计算月、日,参数:年,年内序数,月,日,返回值:false-失败,true-成功

 bool GetDateFromDays(int iYear, int nDays, int iMonth, int iDay);

 //检验年、月、日的合法性,参数:年,月,日,返回值:false-失败,true-成功

 bool DateCheck(int iYear,int iMonth,int iDay);

 //获取农历新年的公历年内序数,参数:农历年,返回值:农历新年的公历年内序数

 int LunarGetNewYearOrdinal(int iLunarYear);

 //获取农历月的天数,参数:农历年,农历月,是否为闰月,返回值:该农历月的天数,为0代表参数无效

 int LunarGetDaysofMonth(int iLunarYear,int iLunarMonth,bool IsLeapMonth);

 //展开大小月数据表(某一年的),参数:农历年,从上一年十一月开始到当前年份(闰)十二月的每月天数,返回值:0-失败,1-成功

 int LunarExpandDX(int iLunarYear,int iDayOfMonth[15]);

 //获取农历某一年的闰月情况,参数:农历年,返回值,该年的闰月月份,0表示无闰月

 int LunarGetLeapMonth(int iLunarYear);

public:

 //公历转农历,参数:公历年、月、日,农历年、月、日,是否为闰月,返回值:false-失败,true-成功

 bool Gongli2Nongli(int iYear,int iMonth,int iDay,int iLunarYear,int iLunarMonth,int iLunarDay,bool iIsLeapMonth);

 //农历转公历,参数:农历年、月、日,是否为闰月,公历年、月、日,返回值:false-失败,true-成功

 bool Nongli2Gongli(int iLunarYear,int iLunarMonth,int iLunarDay,bool iIsLeapMonth,int iYear,int iMonth,int iDay);

};

以下是运行效果

其中年份区间可以自定,这里只为演示而取200年跨度,年份区间在1600年到6999年,使用提取工具(附件中有)提取农历信息。提取的数据进行了压缩,可移植到单片机。

有农历和公历相互转换的函数吗

公历转农历,如图例:

B2="农历"TEXT(A2,"[$-130000]m月d日")----限2007版以上

农历闰月月份会加 1,如润7月会显示8月,8月顺延为9月….,12月顺延为13月。

农历转公历:(供参考,不一定正确,闰年无法转换)

B2=LOOKUP(--SUBSTITUTE(SUBSTITUTE(A2,-30,-28),-29,-27),--TEXT((LEFT(A2,5)"1/1")+ROW($1:$400),"[$-130000]yyyy/m/d"),(LEFT(A2,5)"1/1")+ROW($1:$400))+(--RIGHT(A2,2)28)*2

验算:C2="农历"TEXT(B2,"[$-130000]m月d日")

求农历转公历 公历转农历 农历转公历的程序 C++

void solar()

{

int nyear,nmonth,nday, gyear,gmonth,gday;

long int Ndata,c;

int wei=11,mt,nwhatday=0,runday,runmonth,nm,i,a,whatChunJie,ChunJieYear,zgwhatday,gyday,ms,cz,runt;

char YNrun;

system("cls");

cout"输入需查询的农历年月日(例:2005 05 25)"endl;

cinnyear;

cinnmonth;

cinnday;

if(judge(gyear,gmonth,gday)==0){

cout"error date"endl;

return;

}

runday=(NongliData[nyear-1899]/0x1000)%0x10; //取出判断闰月天数的值

runmonth=(NongliData[nyear-1899]/0x100)%0x10; //取出判断是否闰月闰几月的值

if(runday==1) runt=30;

else runt=29;

if(YNrun=='y')

nm=nmonth; //计算该月前面有几个月

else nm=nmonth-1;//计算在该农历年的第几天

Ndata=NongliData[nyear-1899];

c=Ndata/0x10000;

wei=11;

while(wei=0 nm0){

i=cwei~(~01);

if(i==1) mt=30;

else mt=29;

nwhatday=nwhatday+mt;

nm--;

wei--;

}

if(nmonthrunmonth runmonth!=0){

nwhatday=nwhatday+runt;

}

nwhatday=nwhatday+nday;//计算该年春节在公历年的第几天

ChunJieYear=NongliData[nyear-1899];

a=ChunJieYear%0x100;

whatChunJie=gPastday[a/100]+a%100;

if((ChunJieYear%4==0 ChunJieYear%100!=0 || ChunJieYear%400==0) (a/1002)) whatChunJie++;

zgwhatday=nwhatday+whatChunJie-1;//计算该公历年一年总天数

if(nyear%4==0 nyear%100!=0 || nyear%400==0){

gyday=366;

months[2]=29;

}

else{

gyday=365;

months[2]=28;

}

//换算出公历年份

if(zgwhatdaygyday){

gyear=nyear+1;

zgwhatday=zgwhatday-gyday;

}

else gyear=nyear;

//换算出公历月份

ms=1;

cz=zgwhatday;

gmonth=0;

while(ms13){

cz=cz-months[ms];

if(cz=0) {

gmonth++;

gday=cz+months[ms];

break;

}

gmonth++;

ms++;

}

coutendl"由农历转换成公历查询结果如下"endlendl;

cout"农历:" nyear"年"nmonth"月"nday"日"endl;

coutendl"公历: (公元)"gyear"年"gmonth"月"gday"日"endl;

getch();

}

万年历的c语言程序代码包括节假日农历,农历转公历,公历农历查询某

直接给你整个工程吧,实现了星期计算、公历转农历、农历转公历、节气查询。非常不错的代码,你要的年份范围可以自己决定,支持从公元1600年到公元6400年的四千八百年数据。数据经过我精心设计的原创压缩算法压缩,体积非常小,效率很高。

 密码:n51c  (之前的不知啥原因被HX了,原创的都会被这样,鉴于需要的朋友很多,重新更换了链接)。

如果需要开发日历的完整开发包(支持更长年份),可私信。

200分 excel高手请进 农历转公历的宏代码

身份证记录的不是公历的吗?

YLyear As String, YLShuXing As String, _

Optional IsGetGl As Boolean) As String

' On Error Resume Next

Dim daList(1900 To 2011) As String * 18

Dim conDate As Date, setDate As Date

Dim AddMonth As Integer, AddDay As Integer, AddYear As Integer, getDay As Integer

Dim RunYue As Boolean

If tYear 2010 Or tYear 1901 Then Exit Function '如果不是有效有日期,退出

'1900 to 1909

daList(1900) = "010010110110180131"

daList(1901) = "010010101110000219"

daList(1902) = "101001010111000208"

daList(1903) = "010100100110150129"

daList(1904) = "110100100110000216"

daList(1905) = "110110010101000204"

daList(1906) = "011010101010140125"

daList(1907) = "010101101010000213"

daList(1908) = "100110101101000202"

daList(1909) = "010010101110120122"

daList(1910) = "010010101110000210"

daList(1911) = "101001001101160130"

daList(1912) = "101001001101000218"

daList(1913) = "110100100101000206"

daList(1914) = "110101010100150126"

daList(1915) = "101101010101000214"

daList(1916) = "010101101010000204"

daList(1917) = "100101101101020123"

daList(1918) = "100101011011000211"

daList(1919) = "010010011011170201"

daList(1920) = "010010011011000220"

daList(1921) = "101001001011000208"

daList(1922) = "101100100101150128"

daList(1923) = "011010100101000216"

daList(1924) = "011011010100000205"

daList(1925) = "101011011010140124"

daList(1926) = "001010110110000213"

daList(1927) = "100101010111000202"

daList(1928) = "010010010111120123"

daList(1929) = "010010010111000210"

daList(1930) = "011001001011060130"

daList(1931) = "110101001010000217"

daList(1932) = "111010100101000206"

daList(1933) = "011011010100150126"

daList(1934) = "010110101101000214"

daList(1935) = "001010110110000204"

daList(1936) = "100100110111030124"

daList(1937) = "100100101110000211"

daList(1938) = "110010010110170131"

daList(1939) = "110010010101000219"

daList(1940) = "110101001010000208"

daList(1941) = "110110100101060127"

daList(1942) = "101101010101000215"

daList(1943) = "010101101010000205"

daList(1944) = "101010101101140125"

daList(1945) = "001001011101000213"

daList(1946) = "100100101101000202"

daList(1947) = "110010010101120122"

daList(1948) = "101010010101000210"

daList(1949) = "101101001010170129"

daList(1950) = "011011001010000217"

daList(1951) = "101101010101000206"

daList(1952) = "010101011010150127"

daList(1953) = "010011011010000214"

daList(1954) = "101001011011000203"

daList(1955) = "010100101011130124"

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(1964) = "101001010111000213"

daList(1965) = "010100100110000202"

daList(1966) = "111010010011030121"

daList(1967) = "110110010101000209"

daList(1968) = "010110101010170130"

daList(1969) = "010101101010000217"

daList(1970) = "100101101101000206"

daList(1971) = "010010101110150127"

daList(1972) = "010010101101000215"

daList(1973) = "101001001101000203"

daList(1974) = "110100100110140123"

daList(1975) = "110100100101000211"

daList(1976) = "110101010010180131"

daList(1977) = "101101010100000218"

daList(1978) = "101101101010000207"

daList(1979) = "100101101101060128"

daList(1980) = "100101011011000216"

daList(1981) = "010010011011000205"

daList(1982) = "101001001011140125"

daList(1983) = "101001001011000213"

daList(1984) = "1011001001011A0202"

daList(1985) = "011010100101000220"

daList(1986) = "011011010100000209"

daList(1987) = "101011011010060129"

daList(1988) = "101010110110000217"

daList(1989) = "100100110111000206"

daList(1990) = "010010010111150127"

daList(1991) = "010010010111000215"

daList(1992) = "011001001011000204"

daList(1993) = "011010100101030123"

daList(1994) = "111010100101000210"

daList(1995) = "011010110010180131"

daList(1996) = "010110101100000219"

daList(1997) = "101010110110000207"

daList(1998) = "100100110110150128"

daList(1999) = "100100101110000216"

daList(2000) = "110010010110000205"

daList(2001) = "110101001010140124"

daList(2002) = "110101001010000212"

daList(2003) = "110110100101000201"

daList(2004) = "010110101010120122"

daList(2005) = "010101101010000209"

daList(2006) = "101010101101170129"

daList(2007) = "001001011101000218"

daList(2008) = "100100101101000207"

daList(2009) = "110010010101150126"

daList(2010) = "101010010101000214"

AddYear = tYear

RunYue = False

If IsGetGl Then

AddMonth = Val(Mid(daList(AddYear), 15, 2))

AddDay = Val(Mid(daList(AddYear), 17, 2))

conDate = DateSerial(AddYear, AddMonth, AddDay)

AddDay = tDay

For i = 1 To tMonth - 1

AddDay = AddDay + 29 + Val(Mid(daList(tYear), i, 1))

Next i

'MsgBox DateDiff("d", conDate, Date)

setDate = DateAdd("d", AddDay - 1, conDate)

GetYLDate = setDate

tYear = Year(setDate)

tMonth = Month(setDate)

tDay = Day(setDate)

Exit Function

End If

CHUSHIHUA:

AddMonth = Val(Mid(daList(AddYear), 15, 2))

AddDay = Val(Mid(daList(AddYear), 17, 2))

conDate = DateSerial(AddYear, AddMonth, AddDay)

setDate = DateSerial(tYear, tMonth, tDay)

getDay = DateDiff("d", conDate, setDate)

If getDay 0 Then AddYear = AddYear - 1: GoTo CHUSHIHUA

' addday = NearDay

AddDay = 1: AddMonth = 1

For i = 1 To getDay

AddDay = AddDay + 1

If AddDay = 30 + Mid(daList(AddYear), AddMonth, 1) Or (RunYue And AddDay = 30 + Mid(daList(AddYear), 13, 1)) Then

If RunYue = False And AddMonth = Val("H" Mid(daList(AddYear), 14, 1)) Then

RunYue = True

Else

RunYue = False

AddMonth = AddMonth + 1

End If

AddDay = 1

End If

Next

md$ = "初一初二初三初四初五初六初七初八初九初十十一十二十三十四十五十六十七十八十九二十廿一廿二廿三廿四廿五廿六廿七廿八廿九三十"

dd$ = Mid(md$, (AddDay - 1) * 2 + 1, 2)

mm$ = Mid("正二三四五六七八九十寒腊", AddMonth, 1) + "月"

YouGetDate = DateSerial(AddYear, AddMonth, AddDay)

tiangan$ = "甲乙丙丁戊已庚辛壬癸"

dizhi$ = "子丑寅卯辰巳午未申酉戌亥"

Dim ganzhi(0 To 59) As String * 2

For i = 0 To 59

ganzhi(i) = Mid(tiangan$, (i Mod 10) + 1, 1) + Mid(dizhi$, (i Mod 12) + 1, 1)

'ff$ = ff$ + ganzhi(i)

Next i

'MsgBox ff$, , Len(ff$)

YLyear = ganzhi((AddYear - 4) Mod 60)

shu$ = "鼠牛虎兔龙蛇马羊猴鸡狗猪"

YLShuXing = Mid(shu$, ((AddYear - 4) Mod 12) + 1, 1)

If RunYue Then mm$ = "闰" + mm$

GetYLDate = mm$ + dd$

End Function

农历换公历

公历出生时间:1961年12月11日

农历出生时间:一九六一年 十一月 初四日

公历出生时间:1967年11月27日

农历出生时间:一九六七年 十月 二六日

公历出生时间:1988年11月23日

农历出生时间:一九八八年 十月 十五日

公历出生时间:1993年09月27日

农历出生时间:一九九三年 八月 十二日

1条大神的评论

  • avatar
    访客 2022-07-08 下午 10:00:59

    te = DateSerial(AddYear, AddMonth, AddDay) AddDay = tDay For i = 1 To tMonth - 1 AddDay = AddDay + 29 + Val(Mid(daList(

发表评论