Conversion from a Gregorian calendar to a lunar calendar

Source: Internet
Author: User

'The following is a calendar algorithm for VB <br/> 'Method of defining date data is as follows <br/> 'the first 12 bytes represent 1-12 months as a large month or a small month, 1: 30 days for a large month, 0: 29 days for a small month, <br/> '123456' indicates a leap month, 1: 30 days for a large month, and 0: 29 days for a small month, the fifth digit is the month of the leap month <br/>. If the leap month is not 0, otherwise the month is given, 10, 11, and 12 respectively use A, B, and C as the table <br/> ', that is, the hexadecimal format is used. The last four are the dates of the Year's home lunar new year-that is, the Gregorian calendar of the lunar calendar month <br/> '. For example, 0131 represents. <Br/> the 'getyldate function is used as follows: tYear indicates the year to be input, tMonth indicates the month, tDay indicates the <br/> 'date, YLyear indicates the return value, and the year of the lunar calendar is returned, for example, in year A, YLShuXing returns the <br/> 'object, such as a rat. IsGetGl is used to determine whether to use the lunar calendar to retrieve the Gregorian calendar value. If yes, <br/> 'the first three returns the corresponding Gregorian date, and the return value is a Gregorian date. </P> <p> Function GetYLDate (tYear As Integer, tMonth As Integer, tDay As Integer, _ <br/> YLyear As String, YLShuXing As String, _ <br/> Optional IsGetGl As Boolean) As String </p> <p> On Error Resume Next <br/> Dim daList (1900 To 2011) as String * 18 <br/> Dim conDate As Date, setDate As Date <br/> Dim AddMonth As Integer, AddDay As Integer, AddYear As Integer, getDay As Integer <br/> Dim RunYue As Boolean <br/> If tYear> 2010 Or tYear <1901 Then Exit function' If the date is not valid, exit <br/> '2017 to 1900 <br/> daList (1909) = "1900" <br/> daList (010010110110180131) = "010010101110000219" <br/> daList (1902) = "101001010111000208" <br/> daList (1903) = "010100100110150129" <br/> daList (1904) = "110100100110000216" <br/> daList (1905) = "110110010101000204" <br/> daList (1906) = "011010101010140125" <br/> daList (1907) = "010101101010000213" <br/> daList (1908) = "100110101101000202" <br/> daList (1909) = "010010101110120122" <br/> daList (1910) = "010010101110000210" <br/> daList (1911) = "101001001101160130" <br/> daList (1912) = "101001001101000218" <br/> daList (1913) = "110100100101000206" <br/> daList (1914) = "110101010100150126" <br/> daList (1915) = "101101010101000214" <br/> daList (1916) = "010101101010000204" <br/> daList (1917) = "100101101101020123" <br/> daList (1918) = "100101011011000211" <br/> daList (1919) = "010010011011170201" <br/> daList (1920) = "010010011011000220" <br/> daList (1921) = "101001001011000208" <br/> daList (1922) = "101100100101150128" <br/> daList (1923) = "011010100101000216" <br/> daList (1924) = "011011010100000205" <br/> daList (1925) = "101011011010140124" <br/> daList (1926) = "001010110110000213" <br/> daList (1927) = "100101010111000202" <br/> daList (1928) = "010010010111120123" <br/> daList (1929) = "010010010111000210" <br/> daList (1930) = "011001001011060130" <br/> daList (1931) = "110101001010000217" <br/> daList (1932) = "111010100101000206" <br/> daList (1933) = "011011010100150126" <br/> daList (1934) = "010110101101000214" <br/> daList (1935) = "001010110110000204" <br/> daList (1936) = "100100110111030124" <br/> daList (1937) = "100100101110000211" <br/> daList (1938) = "110010010110170131" <br/> daList (1939) = "110010010101000219" <br/> daList (1940) = "110101001010000208" <br/> daList (1941) = "110110100101060127" <br/> daList (1942) = "101101010101000215" <br/> daList (1943) = "010101101010000205" <br/> daList (1944) = "101010101101140125" <br/> daList (1945) = "001001011101000213" <br/> daList (1946) = "100100101101000202" <br/> daList (1947) = "110010010101120122" <br/> daList (1948) = "101010010101000210" <br/> daList (1949) = "101101001010170129" <br/> daList (1950) = "011011001010000217" <br/> daList (1951) = "101101010101000206" <br/> daList (1952) = "010101011010150127" <br/> daList (1953) = "010011011010000214" <br/> daList (1954) = "101001011011000203" <br/> daList (1955) = "010100101011130124" <br/> daList (1956) = "010100101011000212" <br/> daList (1957) = "101010010101080131" <br/> daList (1958) = "111010010101000218" <br/> daList (1959) = "011010101010000208" <br/> daList (1960) = "101011010101060128" <br/> daList (1961) = "101010110101000215" <br/> daList (1962) = "010010110110000205" <br/> daList (1963) = "101001010111040125" <br/> daList (1964) = "101001010111000213" <br/> daList (1965) = "010100100110000202" <br/> daList (1966) = "111010010011030121" <br/> daList (1967) = "110110010101000209" <br/> daList (1968) = "010110101010170130" <br/> daList (1969) = "010101101010000217" <br/> daList (1970) = "100101101101000206" <br/> daList (1971) = "010010101110150127" <br/> daList (1972) = "010010101101000215" <br/> daList (1973) = "101001001101000203" <br/> daList (1974) = "110100100110140123" <br/> daList (1975) = "110100100101000211" <br/> daList (1976) = "110101010010180131" <br/> daList (1977) = "101101010100000218" <br/> daList (1978) = "101101101010000207" <br/> daList (1979) = "100101101101060128" <br/> daList (1980) = "100101011011000216" <br/> daList (1981) = "010010011011000205" <br/> daList (1982) = "101001001011140125" <br/> daList (1983) = "101001001011000213" <br/> daList (1984) = "1011001001011A0202" <br/> daList (1985) = "011010100101000220" <br/> daList (1986) = "011011010100000209" <br/> daList (1987) = "101011011010060129" <br/> daList (1988) = "101010110110000217" <br/> daList (1989) = "100100110111000206" <br/> daList (1990) = "010010010111150127" <br/> daList (1991) = "010010010111000215" <br/> daList (1992) = "011001001011000204" <br/> daList (1993) = "011010100101030123" <br/> daList (1994) = "111010100101000210" <br/> daList (1995) = "011010110010180131" <br/> daList (1996) = "010110101100000219" <br/> daList (1997) = "101010110110000207" <br/> daList (1998) = "100100110110150128" <br/> daList (1999) = "100100101110000216" <br/> daList (2000) = "110010010110000205" <br/> daList (2001) = "110101001010140124" <br/> daList (2002) = "110101001010000212" <br/> daList (2003) = "110110100101000201" <br/> daList (2004) = "010110101010120122" <br/> daList (2005) = "010101101010000209" <br/> daList (2006) = "101010101101170129" <br/> daList (2007) = "001001011101000218" <br/> daList (2008) = "100100101101000207" <br/> daList (2009) = "110010010101150126" <br/> daList (2010) = "101010010101000214" <br/> daList (2011) = "101101001010000214" <br/> AddYear = tYear <br/> RunYue = False </p> <p> If IsGetGl Then <br/> AddMonth = Val (Mid (daList (addYear ), 15, 2) <br/> AddDay = Val (Mid (daList (AddYear), 17, 2) <br/> conDate = DateSerial (AddYear, AddMonth, AddDay) <br/> AddDay = tDay <br/> For I = 1 To tMonth-1 <br/> AddDay = AddDay + 29 + Val (Mid (daList (tYear), I, 1) <br/> Next I <br/> 'msgbox DateDiff ("d", conDate, Date) <br/> setDate = DateAdd ("d ", addDay-1, conDate) <br/> GetYLDate = setDate <br/> tYear = Year (setDate) <br/> tMonth = Month (setDate) <br/> tDay = Day (setDate) <br/> Exit Function <br/> End If <br/> CHUSHIHUA: <br/> AddMonth = Val (Mid (daList (AddYear), 15, 2) <br/> AddDay = Val (Mid (daList (AddYear), 17, 2 )) <br/> conDate = DateSerial (AddYear, AddMonth, AddDay) <br/> setDate = DateSerial (tYear, tMonth, tDay) <br/> getDay = DateDiff ("d ", conDate, setDate) <br/> If getDay <0 Then AddYear = AddYear-1: GoTo CHUSHIHUA <br/> 'addday = NearDay <br/> addday = 1: addMonth = 1 <br/> For I = 1 To getDay <br/> AddDay = AddDay + 1 <br/> If AddDay = 30 + Mid (daList (AddYear), AddMonth, 1) Or (RunYue And AddDay = 30 + Mid (daList (AddYear), 13, 1 )) then <br/> If RunYue = False And AddMonth = Val ("& H" & Mid (daList (AddYear), 14, 1 )) then <br/> RunYue = True <br/> Else <br/> RunYue = False <br/> AddMonth = AddMonth + 1 <br/> End If <br/> AddDay = 1 <br/> End If </p> <p> Next </p> <p> md $ = "12 october 14, (AddDay-1) * 2 + 1, 2) <br/> mm $ = Mid ("2345x80 or 90 cold wax", AddMonth, 1) + "month" <br/> YouGetDate = DateSerial (AddYear, AddMonth, AddDay) <br/> tiangan $ = "A, B, C, E, Geng, Xin, Xi" <br/> dizhi $ = "Zi, Yin, Mao, Chen, Wu, Wu, Shen, Yu, Hai" <br/> Dim ganzhi (0 to 59) as String * 2 <br/> For I = 0 To 59 <br/> ganzhi (I) = Mid (tiangan $, (I Mod 10) + 1, 1) + Mid (dizhi $, (I Mod 12) + 1, 1) <br/> 'ff $ = ff $ + ganzhi (I) <br/> Next I <br/> 'msgbox ff $, Len (ff $) <br/> YLyear = ganzhi (AddYear-4) Mod 60) <br/> shu $ = "rat, ox, Tiger, Rabbit, dragon, Snake, horse, monkey, chicken, dog, and pig" <br/> YLShuXing = Mid (shu $, (AddYear-4) Mod 12) + 1, 1) <br/> If RunYue Then mm $ = "regular" + mm $ </p> <p> GetYLDate = mm $ + dd $ </p> <p> End Function <br/>

 

Http://www.cx66.com/cxgzs/program/vb/953.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.