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

推荐订阅源

宝玉的分享
宝玉的分享
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
SegmentFault 最新的问题
爱范儿
爱范儿
量子位
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Proofpoint News Feed
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
美团技术团队
Attack and Defense Labs
Attack and Defense Labs
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
月光博客
月光博客
J
Java Code Geeks
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
Cyberwarzone
Cyberwarzone
D
DataBreaches.Net
P
Privacy & Cybersecurity Law Blog
D
Docker
Scott Helme
Scott Helme
S
Schneier on Security
S
Securelist
A
About on SuperTechFans
P
Proofpoint News Feed
V
V2EX
Know Your Adversary
Know Your Adversary
T
Tailwind CSS Blog
I
Intezer
T
Tenable Blog
Last Week in AI
Last Week in AI
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
T
The Exploit Database - CXSecurity.com
GbyAI
GbyAI
IT之家
IT之家
G
GRAHAM CLULEY
Hugging Face - Blog
Hugging Face - Blog
Project Zero
Project Zero
The Register - Security
The Register - Security
C
CERT Recently Published Vulnerability Notes
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
C
Cybersecurity and Infrastructure Security Agency CISA

博客园 - cncxz(虫虫)

在.NET环境下为网站增加IP过滤功能 推荐几个基于.net的cms系统 超赞的10个Windows Live Writer插件 发布ASP.NET应用程序时的10个好习惯(转) 一个基于web的pdf浏览器 ajax跨域访问代理文件下载(asp、php、asp.net) jQuery UI 1.0 已于2007-9-16日正式发布 Visual Studio插件大搜索(60+) 推荐一批基于web的开源html文本编辑器(40+) 终结IE6下背景图片闪烁问题 一个web应用程序统计在线用户列表的东东(带c#源码) 中了网络流氓www.e-jok.cn的招 使用 javascript 标记高亮关键词 Div+Css酷站一箩筐 在win2k3上使用卡巴斯基6.0 发布控件Express.NET.WindowsForms运行时的本地化补丁 创建为ClickOnce清单签名的.pfx格式数字证书 Windows Live Messenger去广告补丁 小发现:sql2005中的异常处理消息框可以直接使用
一个阴历阳历互相转化的类(c#源码)
cncxz(虫虫) · 2007-02-09 · via 博客园 - cncxz(虫虫)

    最近郁闷地发现网上现有的相当一部分万年历上干支纪年的算法都是错误的。因为干支纪年是针对阴历而言的,而生肖属相又跟地支对应,所以元旦和春节之间那段时间在干支纪年法中应该归上一年,以阳历2007年2月9日为例,当日的阴历日期是二〇〇六年十二月廿二日,是丙戌年,即狗年,但是浏览一下目前的万年历,相当一部分都显示成了丁亥年,猪年,比较郁闷~~

    然后就写了一个阴历阳历互相转化的类。

相关代码如下:


    
/// <summary>
    
/// 中国日历信息实体类
    
/// cncxz(虫虫) 2007-2-9
    
/// </summary>

    public sealed class ChineseCalendarInfo
    
{
        
private DateTime m_SolarDate;
        
private int m_LunarYear, m_LunarMonth, m_LunarDay;
        
private bool m_IsLeapMonth = false;
        
private string m_LunarYearSexagenary = null, m_LunarYearAnimal = null;
        
private string m_LunarYearText = null, m_LunarMonthText = null, m_LunarDayText = null;
        
private string m_SolarWeekText = null, m_SolarConstellation = null, m_SolarBirthStone = null;

        
构造函数

        
日历属性

        
/// <summary>
        
/// 根据指定阳历日期计算星座&诞生石
        
/// </summary>
        
/// <param name="date">指定阳历日期</param>
        
/// <param name="constellation">星座</param>
        
/// <param name="birthstone">诞生石</param>

        public static void CalcConstellation(DateTime date, out string constellation, out string birthstone)
        
{
            
int i = Convert.ToInt32(date.ToString("MMdd"));
            
int j;
            
if (i >= 321 && i <= 419)
                j 
= 0;
            
else if (i >= 420 && i <= 520)
                j 
= 1;
            
else if (i >= 521 && i <= 621)
                j 
= 2;
            
else if (i >= 622 && i <= 722)
                j 
= 3;
            
else if (i >= 723 && i <= 822)
                j 
= 4;
            
else if (i >= 823 && i <= 922)
                j 
= 5;
            
else if (i >= 923 && i <= 1023)
                j 
= 6;
            
else if (i >= 1024 && i <= 1121)
                j 
= 7;
            
else if (i >= 1122 && i <= 1221)
                j 
= 8;
            
else if (i >= 1222 || i <= 119)
                j 
= 9;
            
else if (i >= 120 && i <= 218)
                j 
= 10;
            
else if (i >= 219 && i <= 320)
                j 
= 11;
            
else
            
{
                constellation 
= "未知星座";
                birthstone 
= "未知诞生石";
                
return;
            }

            constellation 
= Constellations[j];
            birthstone 
= BirthStones[j];

            
星座划分
        }



        
阴历转阳历

        
从阴历创建日历

        
private static ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar();
        
public const string ChineseNumber = "〇一二三四五六七八九";
        
public const string CelestialStem = "甲乙丙丁戊己庚辛壬癸";
        
public const string TerrestrialBranch = "子丑寅卯辰巳午未申酉戌亥";
        
public const string Animals = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
        
public static readonly string[] ChineseWeekName = new string[] "星期天""星期一""星期二""星期三""星期四""星期五""星期六" };
        
public static readonly string[] ChineseDayName = new string[] {
            
"初一","初二","初三","初四","初五","初六","初七","初八","初九","初十",
            
"十一","十二","十三","十四","十五","十六","十七","十八","十九","二十",
            
"廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"}
;
        
public static readonly string[] ChineseMonthName = new string[] """""""""""""""""""""十一""十二" };
        
public static readonly string[] Constellations = new string[] "白羊座""金牛座""双子座""巨蟹座""狮子座""处女座""天秤座""天蝎座""射手座""摩羯座""水瓶座""双鱼座" };
        
public static readonly string[] BirthStones = new string[] "钻石""蓝宝石""玛瑙""珍珠""红宝石""红条纹玛瑙""蓝宝石""猫眼石""黄宝石""土耳其玉""紫水晶""月长石,血石" };


    }

工程文件下载:https://files.cnblogs.com/cncxz/ChineseCalendar.rar