• ChineseCalendar类[转]


        ///<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();
            }
        }


  • 相关阅读:
    bzoj2669 [cqoi2012]局部极小值 状压DP+容斥
    bzoj2560 串珠子 状压DP
    bzoj2004 [Hnoi2010]Bus 公交线路 矩阵快速幂+状压DP
    「校内训练 2019-04-23」越野赛车问题 动态dp+树的直径
    bzoj5210 最大连通子块和 动态 DP + 堆
    动态 DP 学习笔记
    bzoj4987 Tree 树上背包
    bzoj1190 [HNOI2007]梦幻岛宝珠 背包
    bzoj1004 [HNOI2008]Cards Burnside 引理+背包
    bzoj4922 [Lydsy1706月赛]Karp-de-Chant Number 贪心+背包
  • 原文地址:https://www.cnblogs.com/chenqingwei/p/1754448.html
Copyright © 2020-2023  润新知