vb.net 教程 20-1 农历 2

vb.net 教程 20-1 农历 2,第1张

概述在上一节,我们学习了 ChineseLunisolarCalendar类的简单用法,但是最终获得的结果不是那么符合国人的习俗。 例如,农历的2017年1月23日往往写做: 二O一七年正月廿三日。这一节将完善上一节的结果。 界面还是上一节一样。 主要代码: Dim chineseCallDay() As String = {"", "一", "二", "三", "四", "五", "六",

在上一节,我们学习了 ChineseLunisolarCalendar类的简单用法,但是最终获得的结果不是那么符合国人的习俗。

例如,农历的2017年1月23日往往写做: 二O一七年正月廿三日。这一节将完善上一节的结果。

界面还是上一节一样。

主要代码:

    Dim chineseCallDay() As String = {"","一","二","三","四","五","六","七","八","九"}    Dim chineseCallMonth() As String = {"正","九","十","十一","腊"}    Dim chineseCallYear() As String = {"〇","九"}    Private Sub button1_Click(sender As Object,e As EventArgs) Handles button1.Click        Dim chineseCalendar As New ChineseLunisolarCalendar        Dim Nowdate As DateTime = New DateTime(2017,2,19)        Dim chineseY As Integer = chineseCalendar.GetYear(Nowdate)        Dim chineseM As Integer = chineseCalendar.GetMonth(Nowdate)        Dim chineseD As Integer = chineseCalendar.GetDayOfMonth(Nowdate)        Dim leapMonth As Integer = chineseCalendar.GetLeapMonth(chineseY)        Dim isLeap As Boolean = False        If leapMonth > 0 Then            If leapMonth = chineseM Then                isLeap = True                chineseM -= 1            ElseIf chineseM > leapMonth Then                chineseM -= 1            End If        End If        TextBox1.Text = getChineseYear(chineseY) & "年" & IIf(isLeap,"闰","") & getChineseMonth(chineseM) & "月" & getChineseDay(chineseD)    End Sub    Private Function getChineseDay(ByVal theDay As Integer) As String        Dim callDay As String        If theDay < 10 Then            callDay = "初" & chineseCallDay(theDay)            Return callDay        End If        If theDay >= 10 And theDay < 20 Then            callDay = "十"            callDay &= chineseCallDay(theDay Mod 10)            Return callDay        End If        If theDay >= 20 And theDay < 30 Then            callDay = "廿"            callDay &= chineseCallDay(theDay Mod 10)            Return callDay        End If        If theDay >= 30 Then            callDay = "三十"            callDay &= chineseCallDay(theDay Mod 10)            Return callDay        End If    End Function    Private Function getChineseMonth(ByVal theMonth As Integer) As String        Return chineseCallMonth(theMonth - 1)    End Function    Private Function getChineseYear(ByVal theyear As Integer) As String        Dim callYear As String = ""        Dim strYear As String = CType(theyear,String)        Dim intMIDYear As Integer        For i As Integer = 0 To strYear.Length - 1            intMIDYear = Integer.Parse(strYear.Substring(i,1))            callYear &= chineseCallYear(intMIDYear)        Next        Return callYear    End Function

同时结果还说明了是不是闰月,代码比较简单,不在解说。

运行结果,2017年2月19对应的农历:


学习更多vb.net知识,请参看 vb.net 教程 目录

总结

以上是内存溢出为你收集整理的vb.net 教程 20-1 农历 2全部内容,希望文章能够帮你解决vb.net 教程 20-1 农历 2所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1257796.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存