直接上代码:

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Text;
  4
  5 namespace RSMISClient
  6 {
  7     using System.Globalization;
  8     public static class ChineseDate
  9     {
 10         private static ChineseLunisolarCalendar cCalendar = new ChineseLunisolarCalendar();
 11         //cCalendar.MaxSupportedDateTime 返回支持的最大日期,即2101-1-28
 12         //cCalendar.MinSupportedDateTime  返回支持的最小日期,即1901-2-19
 13
 14         #region 农历年
 15         /// <summary>
 16         /// 十天干
 17         /// </summary>
 18         private static string[] tiangan = { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
 19
 20         /// <summary>
 21         /// 十二地支
 22         /// </summary>
 23         private static string[] dizhi = { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
 24
 25         /// <summary>
 26         /// 十二生肖
 27         /// </summary>
 28         private static string[] shengxiao = { "鼠", "牛", "虎", "免", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
 29
 30         /// <summary>
 31         /// 返回农历天干地支年
 32         /// </summary>
 33         /// <param name="year">农历年</param>
 34         /// <returns></returns>
 35         public static string GetLunisolarYear(int year)
 36         {
 37             if (year > 3)
 38             {
 39                 int tgIndex = (year - 4) % 10;
 40                 int dzIndex = (year - 4) % 12;
 41
 42                 return string.Concat(tiangan[tgIndex], dizhi[dzIndex], "[", shengxiao[dzIndex], "]");
 43             }
 44
 45             throw new ArgumentOutOfRangeException("无效的年份!");
 46         }
 47         #endregion
 48
 49         #region 农历月
 50         /// <summary>
 51         /// 农历月
 52         /// </summary>
 53         private static string[] months = { "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一(冬)", "十二(腊)" };
 54
 55         /// <summary>
 56         /// 返回农历月
 57         /// </summary>
 58         /// <param name="month">月份</param>
 59         /// <returns></returns>
 60         public static string GetLunisolarMonth(int month)
 61         {
 62             if (month < 13 && month > 0)
 63             {
 64                 return months[month - 1];
 65             }
 66
 67             throw new ArgumentOutOfRangeException("无效的月份!");
 68         }
 69         #endregion
 70
 71         #region 农历日
 72         /// <summary>
 73         ///
 74         /// </summary>
 75         private static string[] days1 = { "初", "十", "廿", "三" };
 76
 77         /// <summary>
 78         /// 日
 79         /// </summary>
 80         private static string[] days = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" };
 81
 82         /// <summary>
 83         /// 返回农历日
 84         /// </summary>
 85         /// <param name="day"></param>
 86         /// <returns></returns>
 87         public static string GetLunisolarDay(int day)
 88         {
 89             if (day > 0 && day < 32)
 90             {
 91                 if (day != 20 && day != 30)
 92                 {
 93                     return string.Concat(days1[(day - 1) / 10], days[(day - 1) % 10]);
 94                 }
 95                 else
 96                 {
 97                     return string.Concat(days[(day - 1) / 10], days1[1]);
 98                 }
 99             }
100
101             throw new ArgumentOutOfRangeException("无效的日!");
102         }
103         #endregion
104
105         #region 方法
106         public static string GetChineseDateTime(DateTime datetime)
107         {
108             int lyear = cCalendar.GetYear(datetime);
109             int lmonth = cCalendar.GetMonth(datetime);
110             int lday = cCalendar.GetDayOfMonth(datetime);
111
112             //获取闰月, 0 则表示没有闰月
113             int leapMonth = cCalendar.GetLeapMonth(lyear);
114             bool isleap = false;
115
116             if (leapMonth > 0)
117             {
118                 if (leapMonth == lmonth)
119                 {
120                     //闰月
121                     isleap = true;
122                     lmonth--;
123                 }
124                 else if (lmonth > leapMonth)
125                 {
126                     lmonth--;
127                 }
128             }
129
130             return string.Concat(GetLunisolarYear(lyear), "年 ", isleap ? "闰" : string.Empty, GetLunisolarMonth(lmonth), "月·", GetLunisolarDay(lday));
131         }
132         #endregion
133     }
134
135 }

转载于:https://www.cnblogs.com/Jins/archive/2013/06/06/3122732.html

C# 将系统时间转换成农历时间相关推荐

  1. java 当前时间 转换成 农历(阴历)时间

    package util;import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Ca ...

  2. mysql 格林时间转换_格林时间转换成正常时间

    uscdbmt@rac1:~> date +%s 1414741902 oracle中怎么把这个1414741902转换成正常时间格式 select Numtodsinterval(141474 ...

  3. 将本地时间转换成 UTC 时间,0时区时间

    // 将时间戳转换成日期格式: function timestampToTime(timestamp) { var date = new Date(timestamp);//时间戳为10位需*1000 ...

  4. 当前时间转换成UTC时间

    以下为postman在Pre-request设置当前时间为UTC时间: //格式化时间方法-勿动 Date.prototype.format = function(format){ var o = { ...

  5. 格林时间转换成正常时间

    uscdbmt@rac1:~> date +%s 1414741902 oracle中怎么把这个1414741902转换成正常时间格式 select Numtodsinterval(141474 ...

  6. 将Json转换过来的带T的字符串格式的时间转换成正常时间,并通过指定格式输出

    java中时间接受Json转换时间格式很讨厌,因为json转换的时间带有"T",导致转换时间出错.我提供了下面方法可以转换时间并传出指定格式时间: /*** 将Json转换过来的带 ...

  7. PostgreSQL | 将 timestamptz 格式的UTC时间转换成北京时间

    PostgreSQL | 将 timestamptz 格式的UTC时间转换成北京时间 1.将UTC时间"2020-08-25 02:11:34.59741+00" 转换成北京时间( ...

  8. 日期格式:ddMMyy-hhmmss,格林威治时间转换成北京时间

    有些项目需要第三方的接口来取数据,这样就有个问题,那就是有些字段比较特殊,采用的都是国际标准时间,方便别的语言调用,这样时间差就相差不一样了,需要进行转换. 例如:GPS的数据时间格式:ddMMyy- ...

  9. jQuery 将本地时间转换成 UTC 时间,计算时差,将UTC时间转换成 本地 时间

    //使用方式 let date = 'YYYY-MM-DD'; //你的时间格式(你的时间)//调用 FormatUtcDate(new Date( date + ' 00:00:00 ')) For ...

  10. c语言 北京时间转换utc时间_UTC时间转换成北京时间C语言函数代码

    UTC + 时区差 = 本地时间 时区差东为正,西为负.在此,把东八区时区差记为 +0800, UTC + (+0800) = 本地(北京)时间 (1) 那么,UTC = 本地时间(北京时间))- 0 ...

最新文章

  1. 【缩点】解题报告:luogu P2746 [USACO5.3]校园网Network of Schools(有向图、强连通分量、缩点)
  2. AI传教士和野人渡河问题-实验报告
  3. day 01 ————立志运维的第一天开始,承若书!
  4. 程序员每天到底可以写几行代码?
  5. [LOJ]体育成绩统计 / Score (无脑模拟,没有脑子,就是上!)
  6. kali linux 桌面消失_kalilinux系统设置不见了的解决方案
  7. 使用 javascript 标记高亮关键词
  8. js 的数组怎么push一个对象. Js数组的操作push,pop,shift,unshift JavaScrip
  9. 2sk2225代换3A/1500V中文资料【PDF数据手册】
  10. 微信缓存怎么解决,看这儿
  11. 纯真IP数据库QQWry.dat格式详解
  12. MySQL工作有多努力--了解MySQL Threads Running
  13. Mikrotik RouterOS路由器和华为交换机链路聚合+VRRP+单线多拨
  14. EPMS- 让企业应用更加轻便!
  15. Linux调整网卡MAC地址(指令)
  16. 如何做到两个IP地址是否属于同一网段?
  17. 解决在ros catkin_make编译时出现“make[2]:*** 没有规则可制作目标“的问题
  18. 输入一行字符,分别统计出其数字、大写字母、小写字母和其他字符的个数。
  19. vscode网页显示_vscode怎么打开浏览器
  20. Oracle-OSP-Process->OSP Requisition Qty Is Not Matching With Discrete Job‘s Qty (Doc ID 2289283.1)

热门文章

  1. Operator 基础原理和概念
  2. 深度揭秘Greenplum数据库透明加密
  3. 未来互联网+大数据时代
  4. 【跨境电商】EDM邮件营销完整指南(二):如何开展EDM营销活动
  5. KGB Messenger解题流程
  6. VUE之多元素组件过渡+动画封装
  7. python清屏幕_如何在python中清除屏幕?
  8. CocosCreator快速接入bugly
  9. PageHelper关闭count语句优化
  10. 德国计算机留学难度,德国留学,真的很难毕业吗?德国留学生的真实感受