-
vb.net 教程 20-1 农历 2
版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
在上一节,我们学习了 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 教程 目录
————————————————
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/uruseibest/article/details/75042008
最新更新
求1000阶乘的结果末尾有多少个0
详解MyBatis延迟加载是如何实现的
IDEA 控制台中文乱码4种解决方案
SpringBoot中版本兼容性处理的实现示例
Spring的IOC解决程序耦合的实现
详解Spring多数据源如何切换
Java报错:UnsupportedOperationException in Col
使用Spring Batch实现批处理任务的详细教程
java中怎么将多个音频文件拼接合成一个
SpringBoot整合ES多个精确值查询 terms功能实
数据库审计与智能监控:从日志分析到异
SQL Server 中的数据类型隐式转换问题
SQL Server中T-SQL 数据类型转换详解
sqlserver 数据类型转换小实验
SQL Server数据类型转换方法
SQL Server 2017无法连接到服务器的问题解决
SQLServer地址搜索性能优化
Sql Server查询性能优化之不可小觑的书签查
SQL Server数据库的高性能优化经验总结
SQL SERVER性能优化综述(很好的总结,不要错
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比