网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

vb.net如何显示农历的简单介绍

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

根据经验, 这个算法非常复杂. 经过查找,终于得到一些资料, 在此愿与大家分享。 首先阴历以月为基本单位,一个月以新月出现的那一天为始直至下一个新月出现的前一天。 由于月亮公转的周期介于29到30天之间,阴历的一个月也就由新月出现时刻的早晚或是29天或是30天。 大月为30天,小月为29天。 与阳历不同的是,大小月在不同的年中不固定。 如春节的前一天常称为大年三十,但有不少年如2000年的阴历十二月只有29天。 由于十二个月的时间较阳历年即地球绕太阳公转一周的时间短11天左右. 为了使阴历年与阳历年保持相对稳定,每隔两三年就需要加入一个闰月。 大约每十九年要加入七个闰月。 而二十四节气则是由地球在绕太阳公转的轨道上的位置确定的。 以每年的冬至为始,每15度为一个节气。 是故二十四节气在阳历的每月中有大概固定的日期。 古时以二十四节气指导农耕,这就是阴历又称农历的原因。 其中阳历下半月的十二个节气又称为中气。 中气出现的时刻和闰月的确定有直接的关系。 阴历的计算有下列四条规则: 1.所有新月和节气出现的时刻的计算以东经120度即东八区标准时为准。 但计算1929年以前的阴历时应以北京即东经116度25分的当地时为准。 2.新月出现的一天为一个月的第一天。 如某个节气的出现时刻也在这一天,则不论该节气的出现时刻是否比新月晚,一律算落入新的一个月中。 3.每年的冬至总是落在这年的十一月中。 从一年的冬至的第二天起到下一年冬至这一天止的这段时间称为一岁。 如一岁中有十三个新月出现,则这一岁为闰岁,要加入一个闰月。 4.闰岁中第一个没有中气的月为闰月。 因为一岁中只有十二个中气,所以闰岁中至少有一个月没有中气,也存在有两个月没有中气的可能性。 但这种情况下只有第一个没有中气的月为闰月。 闰月的前一个月为几月则该闰月称为闰几月。 根据以上信息, 我们知道农历是根据天文观测进行指定的(也许可以在天文学的书上找到说明)。 为了简化转换计算, 很多程序人员设计了基于"时间段内查表"方法的例程. 更具体的说明和源码请参考下面这些资料:

成都创新互联是网站建设专家,致力于互联网品牌建设与网络营销,专业领域包括网站设计制作、成都网站设计、电商网站制作开发、成都微信小程序、微信营销、系统平台开发,与其他网站设计及系统开发公司不同,我们的整合解决方案结合了恒基网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,且不断评估并优化我们的方案,为客户提供全方位的互联网品牌整合方案!

实现阳历转阴历算法

下面是一个关于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("本函数只提供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

.net时间怎么显示农历

NET类库提供一些基础的农历类System.Globalization.ChineseLunisolarCalendar

不需要自己写算法。直接用就行。

下边的代码是复制的:

using System;

using System.Collections.Generic;

using System.Text;

namespace System

...{

/**//// summary

/// 中国常用农历日期时间类

/// zj53hao@qq.com

/// /summary

class ChinaDateTime

...{

private int year, month, dayOfMonth;

private bool isLeap;

public DateTime time;

/**//// summary

/// 获取当前日期的农历年

/// /summary

public int Year

...{

get ...{ return year; }

}

/**//// summary

/// 获取当前日期的农历月份

/// /summary

public int Month

...{

get ...{ return month; }

}

/**//// summary

/// 获取当前日期的农历月中天数

/// /summary

public int DayOfMonth

...{

get ...{ return dayOfMonth; }

}

/**//// summary

/// 获取当前日期是否为闰月中的日期

/// /summary

public bool IsLeap

...{

get ...{ return isLeap; }

}

System.Globalization.ChineseLunisolarCalendar cc;

/**//// summary

/// 返回指定公历日期的阴历时间

/// /summary

/// param name="time"/param

public ChinaDateTime(DateTime time)

...{

cc = new System.Globalization.ChineseLunisolarCalendar();

if (time cc.MaxSupportedDateTime || time cc.MinSupportedDateTime)

throw new Exception("参数日期时间不在支持的范围内,支持范围:" + cc.MinSupportedDateTime.ToShortDateString()+"到"+cc.MaxSupportedDateTime.ToShortDateString());

year = cc.GetYear(time);

month = cc.GetMonth(time);

dayOfMonth = cc.GetDayOfMonth(time);

isLeap = cc.IsLeapMonth(year, month);

if (isLeap) month -= 1;

this.time = time;

}

/**//// summary

/// 返回当前日前的农历日期。

/// /summary

public static ChinaDateTime Now

...{

get ...{ return new ChinaDateTime(DateTime.Now); }

}

/**//// summary

/// 返回指定农历年,月,日,是否为闰月的农历日期时间

/// /summary

/// param name="Year"/param

/// param name="Month"/param

/// param name="DayOfMonth"/param

/// param name="IsLeap"/param

public ChinaDateTime(int Year, int Month, int DayOfMonth, bool IsLeap)

...{

if (Year = cc.MaxSupportedDateTime.Year || Year = cc.MinSupportedDateTime.Year)

throw new Exception("参数年份时间不在支持的范围内,支持范围:" + cc.MinSupportedDateTime.ToShortDateString() + "到" + cc.MaxSupportedDateTime.ToShortDateString());

if (Month 1 || Month 12)

throw new Exception("月份必须在1~12范围");

cc = new System.Globalization.ChineseLunisolarCalendar();

if(cc.GetLeapMonth(Year)!=MonthIsLeap)

throw new Exception("指定的月份不是当年的闰月");

if (cc.GetDaysInMonth(Year, IsLeap ? Month + 1 : Month) DayOfMonth || DayOfMonth 1)

throw new Exception("指定的月中的天数不在当前月天数有效范围");

year = Year;

month = Month;

dayOfMonth = DayOfMonth;

isLeap = IsLeap;

time = DateTime.Now;

}

/**//// summary

/// 获取当前农历日期的公历时间

/// /summary

public DateTime ToDateTime()

...{

return cc.ToDateTime(year, isLeap ? month + 1 : month, dayOfMonth, time.Hour, time.Minute, time.Second, time.Millisecond);

}

/**//// summary

/// 获取指定农历时间对应的公历时间

/// /summary

/// param name="CnTime"/param

/// returns/returns

public static DateTime ToDateTime(ChinaDateTime CnTime)

...{

return CnTime.ToDateTime();

}

/**//// summary

/// 获取指定公历时间转换为农历时间

/// /summary

/// param name="Time"/param

/// returns/returns

public static ChinaDateTime ToChinaDateTime(DateTime Time)

...{

return new ChinaDateTime(Time);

}

/**//// summary


网站名称:vb.net如何显示农历的简单介绍
标题URL:http://bjjierui.cn/article/dopdiod.html

其他资讯