zoukankan      html  css  js  c++  java
  • c# 公元转农历

     代码如下:

    void Main()
    {
        //农历转阳历
        var lunar = new System.Globalization.ChineseLunisolarCalendar();
        var date = lunar.ToDateTime(2020, 1, 1, 0, 0, 0, 0); //将2020年正月初一转为阳历,如果闰月,则月份加1。2020年有闰四月,则闰四月传5, 本年度之后的月份依次类推
        Console.WriteLine(date);
    
        //阳历转阴历
        date = new DateTime(2020, 1, 1);
        var leapMonth = lunar.GetLeapMonth(date.Year);  //获取当年农历闰月
        if (leapMonth == 0) //当年没有闰月
        {
            var lunarDate = lunar.GetYear(date) + "" + lunar.GetMonth(date) + "" + lunar.GetDayOfMonth(date) + "";
            Console.WriteLine(lunarDate);
        }
        else //当年有闰月
        {
            //因闰月之后月份都加了一,所以要减一
            var month = lunar.GetMonth(date) >= leapMonth ? lunar.GetMonth(date) - 1 : lunar.GetMonth(date);
            var lunarDate = lunar.GetYear(date) + "" + (lunar.GetMonth(date) == leapMonth ? "" : string.Empty) + month + "" + lunar.GetDayOfMonth(date) + "";
            Console.WriteLine(lunarDate);
        }
    }
  • 相关阅读:
    mongo常用查询
    MongoDB
    python连接mongo
    linux 硬盘
    kali 日志
    linux 命令
    grep
    linux shell
    linux 匹配字符串是否为数字
    linux 第一题 计算题
  • 原文地址:https://www.cnblogs.com/nanfei/p/10737208.html
Copyright © 2011-2022 走看看