zoukankan      html  css  js  c++  java
  • C# 阳历转农历

    你妹的sb 原文 C#(ASP.NET)公历转农历的简单方法

    Dot Net 平台,对全球化的支持做的非常好,不得不称赞一个

    通常,将公历转为农历,是个非常烦的事情,需要整理闰年、闰月等的对照表。

    在.Net平台上,有了国际化的支持,这些东西,都已经提供了 ,我们需要做的,只是利用一下而已。

    话不多说,直接上代码:

    /// <summary>
    /// 公历转为农历的函数
    /// </summary>
    /// <remarks>作者:DeltaCat</remarks>
    /// <example>网址:http://www.zu14.cn</example>
    /// <param name="solarDateTime">公历日期</param>
    /// <returns>农历的日期</returns>
    static string SolarToChineseLunisolarDate(DateTime solarDateTime)
    {
        System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar();
    
        int year = cal.GetYear(solarDateTime);
        int month = cal.GetMonth(solarDateTime);
        int day = cal.GetDayOfMonth(solarDateTime);
        int leapMonth = cal.GetLeapMonth(year);
        return string.Format("农历{0}{1}({2})年{3}{4}月{5}{6}"
                            , "甲乙丙丁戊己庚辛壬癸"[(year - 4) % 10]
                            , "子丑寅卯辰巳午未申酉戌亥"[(year - 4) % 12]
                            , "鼠牛虎兔龙蛇马羊猴鸡狗猪"[(year - 4) % 12]
                            , month == leapMonth ? "闰" : ""
                            , "无正二三四五六七八九十冬腊"[leapMonth > 0 && leapMonth <= month ? month - 1 : month]
                            , "初十廿三"[day / 10]
                            , "日一二三四五六七八九"[day % 10]
                            );
    }

    使用的方法非常简单:

    string 农历 = SolarToChineseLunisolarDate(DateTime.Today);

  • 相关阅读:
    七、文件的排序、合并和分割
    六、awk编程
    五、sed命令
    四、grep命令
    三、正则表达式
    二、Linux文件系统和文本编辑器
    一、shell基础知识点
    mysql实现交易编码生成(代替oracle的序列)
    新安装Centos无法访问网络
    uiview 动画
  • 原文地址:https://www.cnblogs.com/arxive/p/6009550.html
Copyright © 2011-2022 走看看