zoukankan      html  css  js  c++  java
  • 由.Net类库提供的农历计算(C#农历)-获取当前日期的农历日期

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Globalization;

    /**
     * 说明:在东亚各国,除了通用的公元纪年之外,还有各自以前使用的阴历纪年法,在.net2.0种增加了针对东亚各国的日历类EastAsianLunisolarCalendar,
     * 它是一个抽象类,有各种针对不同国家的的子类,其中ChineseLunisolarCalendar就是针对中国的日历类,它提公元纪年与中国传统农历纪年之间的相互转换
     * 利用它可以计算天干地支等有关农历的信息,本程序就是来简单展示这个类的用法。它能计算的农历范围从公历1901-2-19至2101-1-28。
     * 首发地址:http://blog.csdn.net/zhoufoxcn/archive/2007/11/21/1896258.aspx
     
    */
    namespace ChineseCalendar
    {
        
    class Program
        {
            
    private static ChineseLunisolarCalendar chineseDate = new ChineseLunisolarCalendar();
            
    static void Main(string[] args)
            {
                
    //ChineseLunisolarCalendar chineseDate = new ChineseLunisolarCalendar();
                ShowYearInfo();
                ShowCurrentYearInfo();
                Console.ReadLine();
            }
            
    /// <summary>
            
    /// 展示阴历年份信息
            
    /// </summary>
            public static void ShowYearInfo()
            {
                
    for (int i = chineseDate.MinSupportedDateTime.Year; i < chineseDate.MaxSupportedDateTime.Year; i++)
                {
                    Console.WriteLine(
    "年份:{0},月份总数:{1},总天数:{2},干支序号:{3}", i, chineseDate.GetMonthsInYear(i),chineseDate.GetDaysInYear(i)
                        ,chineseDate.GetSexagenaryYear(
    new DateTime(i,3,1)));
                }
            }
            
    /// <summary>
            
    /// 展示当前年份信息
            
    /// </summary>
            public static void ShowCurrentYearInfo()
            {
                Console.WriteLine(
    "今年的阴历时间:{0}年{1}月{2}日。", chineseDate.GetYear(DateTime.Now),chineseDate.GetMonth(DateTime.Now),chineseDate.GetDayOfMonth(DateTime.Now));
                Console.WriteLine(
    "今年阴历天数:{0},今年{1}闰年", chineseDate.GetDaysInYear(DateTime.Now.Year),(chineseDate.IsLeapYear(DateTime.Now.Year)==true)?"":"不是");
                Console.WriteLine(
    "今年农历每月的天数:");
                
    for (int i = 1; i <= chineseDate.GetMonthsInYear(DateTime.Now.Year); i++)
                {
                    Console.Write(
    "{0,-5}",chineseDate.GetDaysInMonth(DateTime.Now.Year,i));
                }
            }
        }
    }

    运行结果:

  • 相关阅读:
    第17章 标准库特殊设施
    第16章 模板与泛型编程
    String、StringBuffer、StringBuilder的区别
    Mycat分库分表 读写分离 主从切换
    nginx的配置与使用
    kafka的使用
    zookeeper的使用
    mysql数据库优化
    mysql数据库事务详细剖析
    new Thread的弊端及Java四种线程池的使用
  • 原文地址:https://www.cnblogs.com/prvin/p/3356645.html
Copyright © 2011-2022 走看看