VB.NET的阳历与农历转换的算法

原创 2004年08月27日 00:49:00
'下面是一个关于VB的农历算法<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    '日期数据定义方法如下

    '前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("本函数只提供1900年至2011年的日历转换!")

        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

            Try

                vtDate = 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

                    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

            Return AddYear & "-" & AddMonth & "-" & AddDay

        End If

 

    End Function

 

    Enum 转换方式

        阴历转阳历 = 1

        阳历转阴历 = 0

    End Enum

vb.net农历计算函数

  • 2008年09月26日 14:36
  • 9KB
  • 下载

C#、Asp.Net 农历与阴历之间相互转化工具类

在做一些数据统计或者时间方面的开发时,通常会遇到需要对时间的农历与阴历之间相互进行转化,需要查询当前日期是否为春节或其他节日,判断是否为春节期间“jrDate == "除夕" || jrDate ==...
  • qq285679784
  • qq285679784
  • 2016年04月28日 18:04
  • 1470

VB计算农历的算法

 下面是一个关于VB的农历算法日期数据定义方法如下前12个字节代表1-12月为大月或是小月,1为大月30天,0为小月29天,第13位为闰月的情况,1为大月30天,0为小月29天,第14位为闰月的月份,...
  • ehung
  • ehung
  • 2005年11月27日 19:40
  • 790

小小日历表,用VB.NET编写的日历表,可以显示农历,日期,时间,和星期.

  • 2010年01月13日 16:30
  • 12KB
  • 下载

农历 阴历 转换阳历算法

声明:代码来源于网络,只是改的易于阅读与理解而已 #include #include typedef struct _lunar{ int year; int month; ...
  • handyhuang
  • handyhuang
  • 2015年12月31日 09:58
  • 2157

C++阳历转阴历算法及实现

关于日历的一些基本常识: 阳历:每年12个月,1、3、5、7、8、10、12月都为31天;2月份平年28天,闰年((year%400==0)||(year%4==0&&year%100!=0))为2...
  • shufac
  • shufac
  • 2014年05月29日 23:35
  • 1812

公历转农历算法(C语言)

#include #include #include unsigned int LunarCalendarDay; unsigned int LunarCalendarTable[199] =...
  • syrchina
  • syrchina
  • 2013年01月24日 19:34
  • 10064

阳历转换成阴历PHP实现详解

农历与阴历相关概念;阳历转换成阴历总体思路;怎样计算某一年的生肖;怎样计算天干地支;具体的程序实现;农历十六进制数据解析;为什么选择阳历1900.1.31作为参考点;怎样计算农历y年有多少天;PHP ...
  • hsd2012
  • hsd2012
  • 2016年06月20日 17:52
  • 3031

开源多语言公历农历转换

Lunar Solar Calendar Converter 公历(阳历) 农历(阴历)转换,支持时间段从1900-2100 如果需要更长的时间段,利用generate.htm生成的数...
  • problc
  • problc
  • 2015年01月19日 14:00
  • 9264

Android移动开发-Android开发日历时常用的农历和公历换算代码工具类

下面是与Android开发日历时常用的有关农历计算、公历计算、二十四气节相关的代码工具类的代码。Constant.java逻辑代码如下: package com.fukaimei.calendar.c...
  • fukaimei
  • fukaimei
  • 2017年11月03日 23:19
  • 424
收藏助手
不良信息举报
您举报文章:VB.NET的阳历与农历转换的算法
举报原因:
原因补充:

(最多只允许输入30个字)