實現陽曆轉陰曆演算法

2021-12-25 23:22:11 字數 6991 閱讀 8727

1樓:匿名使用者

下面是一個關於vb的農曆演算法

'日期資料定義方法如下

'前12個位元組代表1-12月為大月或是小月,1為大月30天,0為小月29天;

'第13位為閏月的情況,1為大月30天,0為小月29天;

'第14位為閏月的月份,如果不是閏月為0,否則給出月份,10、11、12分別用a、b、c來表示,即使用16進位制;

'最後4位為當年家農曆新年-即農曆1月1日所在公曆的日期,如0131代表1月31日。

function getchgdate(byval vdate as string, byval chgtype as 轉換方式) as string

dim vvdate() as string = split(vdate, "-")

if vvdate(0) > 2011 or vvdate(0) < 1900 then

throw new notsupportedexception("本函式只提供2023年至2023年的日曆轉換!")

end if

dim addmonth, addday, addyear, getday, i as integer

dim runyue as boolean

dim condate as datetime

dim dalist(2011) as string

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"

dalist(2011) = "101101001010000214"

addyear = vvdate(0)

if chgtype = 轉換方式.陰曆轉陽曆 then

addmonth = val(mid(dalist(addyear), 15, 2))

addday = val(mid(dalist(addyear), 17, 2))

condate = dateserial(addyear, addmonth, addday)

addday = vvdate(2)

for i = 1 to vvdate(1) - 1

addday = addday + 29 + val(mid(dalist(vvdate(0)), i, 1))

next i

return dateadd(dateinterval.day, addday - 1, condate)

else

chushihua:

addmonth = val(mid(dalist(addyear), 15, 2))

addday = val(mid(dalist(addyear), 17, 2))

condate = dateserial(addyear, addmonth, addday)

dim vtdate as datetime

tryvtdate = ctype(vdate, datetime)

catch ex as exception

throw new notsupportedexception("陽曆日期輸入錯誤!")

end try

getday = datediff(dateinterval.day, condate, vtdate)

if getday < 0 then addyear = addyear - 1 : goto chushihua

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

runyue = true

else

runyue = false

addmonth = addmonth + 1

end if

addday = 1

end if

next

return addyear & "-" & addmonth & "-" & addday

end if

end function

enum 轉換方式

陰曆轉陽曆 = 1

陽曆轉陰曆 = 0

end enum

陰曆轉陽曆是多少

央央 陰曆1991年1月16日陽曆是1991年3月2日 雙魚座 雙魚座 pisces 2月19日 3月20日 主宰行星 海王星 屬性 水相星座 陰陽性 陰性 變動星座 誕生石 海藍寶石 誕生花 水百合黃水仙 誕生樹 柳樹 適合顏色 淡綠青綠淡粉 幸運金屬 鉑金 幸運數字 2 6 建議送他的禮物 印象...

FPGA實現照相,用FPGA實現演算法是什麼意思

輸入 處理 輸出 一部分一部分來考慮就行了,輸入端就是攝像頭,然後你看攝像頭出來的是什麼資料。處理端就要對獲得的影象資料進行處理,放大縮小或者移動存放輸出端就是顯示端了,將 顯示到顯示屏上,或者通過資料線傳到電腦或者其他裝置上 三個環節的功能考慮清楚了,你就知道應該怎麼做了 下面是對你的問題的回答 ...

生日是按陽曆還是陰曆,生日是陽曆還是陰曆?

生日你可以按陰曆 陽曆各過一次,陰曆陽曆相差有點大,基本好幾十年或好幾百年才會重合一次!但是通常是算陽曆,因為你身份證上是陽曆的日期 辦各種手續 證件啊都是按照身份證來的!至於屬相 生辰八字就要按照陰曆來了!希望我的回答能解決你的問題 純手工碼字,望採納!星座上的生日是按農曆還是公曆?查自己的本命太...