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

推荐订阅源

GbyAI
GbyAI
Cloudbric
Cloudbric
aimingoo的专栏
aimingoo的专栏
D
Docker
量子位
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - Franky
S
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Tor Project blog
Google Online Security Blog
Google Online Security Blog
T
Tenable Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
I
InfoQ
罗磊的独立博客
P
Palo Alto Networks Blog
Security Latest
Security Latest
K
Kaspersky official blog
Apple Machine Learning Research
Apple Machine Learning Research
I
Intezer
C
Cybersecurity and Infrastructure Security Agency CISA
TaoSecurity Blog
TaoSecurity Blog
S
Security @ Cisco Blogs
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
Simon Willison's Weblog
Simon Willison's Weblog
V
V2EX
N
Netflix TechBlog - Medium
爱范儿
爱范儿
S
Secure Thoughts
S
Securelist
MyScale Blog
MyScale Blog
Webroot Blog
Webroot Blog
IT之家
IT之家
Cyberwarzone
Cyberwarzone
Martin Fowler
Martin Fowler
Project Zero
Project Zero
NISL@THU
NISL@THU
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hacker News: Front Page
H
Heimdal Security Blog
博客园_首页
V
Vulnerabilities – Threatpost
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
The Cloudflare Blog

博客园 - 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