///<summary>
    ///Title: ChineseCalendar类
    ///Description: 中文日期工具类
    ///@author 万灵杰[作者]
    ///@version 1.0.0.0
    ///@date 2009年7月30日
    ///@modify 
    ///@date 
    /// </summary>
    public class ChineseCalendar
    {
        private static readonly string[] Animals = new string[] { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
        private static readonly string[] arrCnNames = new string[] { "日", "一", "二", "三", "四", "五", "六" };
        private static ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar();
        private const string CelestialStem = "甲乙丙丁戊己庚辛壬癸";
        private static readonly string[] ChineseDayName = new string[] { 
            "初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", 
            "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十"
         };
        private static readonly string[] ChineseMonthName = new string[] { "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };
        private static string ChineseNumber = "〇一二三四五六七八九";
        private const string TerrestrialBranch = "子丑寅卯辰巳午未申酉戌亥";

public static string Now
        {
            get
            {
                return GetChineseCalendar(DateTime.Now);
            }
        }

public static string GetAnimals(DateTime time)
        {
            return Animals[(calendar.GetYear(time) - 4) % 12];
        }

public static string GetChineseCalendar(DateTime time)
        {
            return string.Format("{0}年{1}月{2}", GetStemBranch(time), GetMonth(time), GetDay(time));
        }

public static string GetDay(DateTime time)
        {
            return ChineseDayName[calendar.GetDayOfMonth(time) - 1];
        }

public static string GetMonth(DateTime time)
        {
            int month = calendar.GetMonth(time);
            int year = calendar.GetYear(time);
            int num3 = 0;
            for (int i = 3; i <= month; i++)
            {
                if (calendar.IsLeapMonth(year, i))
                {
                    num3 = i;
                    break;
                }
            }
            if (num3 > 0)
            {
                month--;
            }
            return (((num3 == (month + 1)) ? "闰" : "") + ChineseMonthName[month - 1]);
        }

public static string GetStemBranch(DateTime time)
        {
            int sexagenaryYear = calendar.GetSexagenaryYear(time);
            int startIndex = (sexagenaryYear % 12) - 1;
            if (startIndex > 11)
            {
                startIndex = 0;
            }
            if (startIndex < 0)
            {
                startIndex = 11;
            }
            int num3 = (sexagenaryYear % 10) - 1;
            if (num3 > 9)
            {
                num3 = 0;
            }
            if (num3 < 0)
            {
                num3 = 9;
            }
            return ("甲乙丙丁戊己庚辛壬癸".Substring(num3, 1) + "子丑寅卯辰巳午未申酉戌亥".Substring(startIndex, 1));
        }

public static string GetWeekDayName(DateTime time)
        {
            return ("星期" + arrCnNames[(int)time.DayOfWeek]);
        }

public static string GetYear(DateTime time)
        {
            StringBuilder builder = new StringBuilder();
            int year = calendar.GetYear(time);
            do
            {
                int num2 = year % 10;
                builder.Insert(0, ChineseNumber[num2]);
                year /= 10;
            }
            while (year > 0);
            return builder.ToString();
        }
    }

转载于:https://www.cnblogs.com/chenqingwei/archive/2010/06/09/1754448.html

ChineseCalendar类[转]相关推荐

  1. 自己搜集编写的Delphi 通用函数

    { ********************************************************************** } { Currency Common Functio ...

  2. 推荐一个不到2MB的C#开发工具箱,集成了上千个常用操作类

    今天给大家推荐一个C#开发工具箱,涵盖了所有常用操作类,体积小.功能强大. 项目简介 C# 开发工具箱.大都是静态类,加密解密,反射操作,权重随机筛选算法,分布式短id,表达式树,linq扩展,文件压 ...

  3. C#中使用新增类实现农历

    using System; using System.Collections; using System.Text; using System.Globalization; namespace 农历 ...

  4. 一个阴历阳历互相转化的类(c#源码)

    最近郁闷地发现网上现有的相当一部分万年历上干支纪年的算法都是错误的.因为干支纪年是针对阴历而言的,而生肖属相又跟地支对应,所以元旦和春节之间那段时间在干支纪年法中应该归上一年,以阳历2007年2月9日 ...

  5. 中国农历1900-2100算法工具类

    Github工程源码:<a target=_blank href="https://github.com/SalamanderJY/ChineseCalendar">h ...

  6. 分享一个自己写的取中国农历相关数据的类。包含:农历年月日,生肖,星座,年龄,天干,地支等方法...

    分享一个自己写的取中国农历相关数据的类.包含:农历年月日,生肖,星座,年龄,天干,地支等方法.此类自己花了一上午的时间写的,适用于像相亲网等类似的网站 主要使用了微软针对东亚地区的农历类Chinese ...

  7. 继承WebMvcConfigurer 和 WebMvcConfigurerAdapter类依然CORS报错? springboot 两种方式稳定解决跨域问题

    继承WebMvcConfigurer 和 WebMvcConfigurerAdapter类依然CORS报错???springboot 两种方式稳定解决跨域问题! 之前我写了一篇文章,来解决CORS报错 ...

  8. MybatisPlus忽略实体类中的非数据库字段、JPA忽略实体类中的非数据库字段、HeHibernate忽略实体类中的非数据库字段

    mybatis plus忽略映射字段时可以在实体类属性上使用以下注解: @TableField(exist = false):表示该属性不为数据库表字段,但又是必须使用的. @TableField(e ...

  9. IDEA中根据数据库自动生成实体类,并自定义所生成的实体类中的注解 @Table @Id @...

    使用IDEA项目添加Hibernate扩展,生成实体类并配置实体类中的注解 一.使用Hibernate自动生成实体类 1.在项目上右键,选择Add Framework Support找到 Hibern ...

最新文章

  1. 【Spring】—— 自动装配
  2. 没有为类型定义方法怎么办_拼多多开店没有流量怎么办?有什么方法?新手必看!...
  3. 水电缴费系统php源码_简易水电费管理系统源程序代码
  4. 十道常见的MyBatis 面试题
  5. Python3解决UnicodeDecodeError:'utf-8' codec can't decode byte..问题终极解决方案
  6. bootstrap 点击按钮刷新_Spring Cloud 中的 Bootstrap 上下文
  7. mysql根据排序取前百分之二十_MySQL 性能优化 MySQL常见SQL错误用法
  8. JSK-119 求解a到100的和【入门】
  9. python学习-如何高效学 Python?
  10. 通过VBA实现FTP自动下载及关键字检索等功能
  11. JavaScript|表格背景颜色改变页面
  12. WebGoat教程解析——Hijack a Session
  13. 用Android studio设计贺卡,功能强大的贺卡设计制作软件推荐:Hallmark Card Studio
  14. 【Unity】OnePieceFTG(五)游戏流程
  15. linux生成.so库,调用.so库函数
  16. 华为推送 简介 集成
  17. 女生学习软件测试好找工作吗?
  18. vscode和IDEA分别如何克隆git上的项目
  19. Chapter7 Cloud Infrastructure Mechanisms
  20. 微信视频号服务商怎么赚钱?

热门文章

  1. Go 学习笔记(62)— Go 中 switch 语句中的 switch 表达式和 case 表达式之间的关系
  2. centos7samba服务的搭建
  3. Intellij IDEA 添加jar包
  4. 8080CPU寄存器划分
  5. Clang:LLVM 的 C 语言家族前端
  6. NVIDIA® TensorRT™ supports different data formats
  7. 使用多个推理芯片需要仔细规划
  8. 使用Keil语言的嵌入式C编程教程(下)
  9. 3D车道线检测:Gen-LaneNet
  10. web站点的欢迎页面