惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
宝玉的分享
宝玉的分享
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 三生石上(FineUI控件)
IT之家
IT之家
博客园 - Franky
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Blog — PlanetScale
Blog — PlanetScale
Recent Announcements
Recent Announcements
Stack Overflow Blog
Stack Overflow Blog
T
Threatpost
aimingoo的专栏
aimingoo的专栏
博客园_首页
Know Your Adversary
Know Your Adversary
T
Threat Research - Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Security Latest
Security Latest
T
Tailwind CSS Blog
The Hacker News
The Hacker News
P
Palo Alto Networks Blog
Latest news
Latest news
G
GRAHAM CLULEY
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
A
Arctic Wolf
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
InfoQ
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 叶小钗
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
Last Week in AI
Last Week in AI
罗磊的独立博客
博客园 - 聂微东
Simon Willison's Weblog
Simon Willison's Weblog
Scott Helme
Scott Helme
T
Tenable Blog
O
OpenAI News
The Cloudflare Blog
大猫的无限游戏
大猫的无限游戏
L
LINUX DO - 热门话题
美团技术团队

博客园 - kuning的程序博客

第一章 第二课 Using Resources 第一章 第一课 Using WPF Control Cmd,powershell 参考 百度WSUS 我也转关于软件测试的文章 了解WMI 英文面试题 据说是微软面试哦 算法 之 哥德巴赫猜想 - kuning的程序博客 C# 理论学习 之 面向对象设计 C# 理论学习 之 类、组,名称空间 C# 深入学习 之 Winform记录日志 C#深入学习 之 委托和事件 C#数据结构-排序之快速排序法 .Net本地化资源 PHP之安装篇 Sql Server中的行列互换 再叙2005Web控件(一) - kuning的程序博客 - 博客园 Poket PC 与 sqlserver2000(以上) RDA 方案
算法 之 万年历
kuning的程序博客 · 2010-03-29 · via 博客园 - kuning的程序博客
一、代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace PowerCalendar
{
    /// <summary>
    /// 万年历
    /// </summary>
    public partial class Form1 : Form
    {
        const string CelestlalStem = "甲乙丙丁戊己庚辛壬癸";
        const string TerrestrialBranch = "子丑寅卯辰已午未申酉戌亥";
        const string TeeYear = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
        string[] ChinesDayNames;
        string[] ChinesMonthNames = new string[12] { "", "", "", "", "", "", "", "", "", "", "", "" };
        const string ChineseFormat = "{0}{1}年{2}月{3} {4}年";
        ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar();
        public Form1()
        {
            InitializeComponent();
            ChinesDayNames = new string[31]{"初一", "初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四",
                                                 "十五","十六","十七","十八","十九","廿十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","卅十","卅一"};
        }


        private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {
            this.toolTip1.Show(GetStemBranch(monthCalendar1.SelectionStart), this.monthCalendar1, this.monthCalendar1.Location, 5000);
            this.label1.Text = GetStemBranch(monthCalendar1.SelectionStart);
        }

        /// <summary>
        /// 显示今天日期
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Text=GetStemBranch(this.monthCalendar1.TodayDate);
            label1.BackColor=Color.Wheat;
        }

        /// <summary>
        /// 返回阴历日期
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public string GetStemBranch(DateTime date)
        {
            int year = calendar.GetSexagenaryYear(date);
            int celestial = calendar.GetCelestialStem(year);
            int branch = calendar.GetTerrestrialBranch(year);
            return string.Format(ChineseFormat, CelestlalStem[celestial - 1], TerrestrialBranch[branch - 1], GetMonth(date), GetDayDate(date), GetYear(date));
        }
        /// <summary>
        /// 返回阴历月份
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public string GetMonth(DateTime date)
        {
            int month = calendar.GetMonth(date);
            bool isLeap = false;
            if (calendar.IsLeapMonth(calendar.GetYear(date), calendar.GetMonth(date)))//闰月的话月份减一
            {
                month--;
                isLeap = true;
            }

            return (isLeap?"":"")+ChinesMonthNames[month - 1];

        }

        /// <summary>
        /// 返回阴历天的记法
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public string GetDayDate(DateTime time)
        {

            int day = calendar.GetDayOfMonth(time);
            return ChinesDayNames[day - 1];
        }
        /// <summary>
        /// 返回阴历年的记法
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public string GetYear(DateTime date)
        {

            int year = calendar.GetSexagenaryYear(date);//60甲子年
            int branch = calendar.GetTerrestrialBranch(year);//地支
            return TeeYear[branch-1].ToString();

        }
    }
}

二、效果:

cl