频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

c#中国农历时间类

来源:qqread 作者:佚名 出处:巧巧读书 2008-04-23 进入讨论组
  • 关 键 词:
  • .net
下一页 1 2 

    原来还准备自己写算法,并研究农历规则。发现那太难和麻烦了,光是农历的推算那就我等专门研究历法的人一下搞懂的。后来发现。NET类库也提供一些基础的农历类System.Globalization.ChineseLunisolarCalendar。我改装了一下如DateTime时间形式。代码如下。

实现了 公历农历转换的功能。但是只能算到1900~2100年之间的。基本够日常使用了。源代码如下。
    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace System
    ...{
    /**//// <summary>
    /// 中国常用农历日期时间类
    /// zj53hao@qq.com   http://hi.csdn.net/zj53hao
    /// </summary>
    class ChinaDateTime
    ...{
        private int year, month, dayOfMonth;
        private bool isLeap;
        public DateTime time;

        /**//// <summary>
        /// 获取当前日期的农历年
        /// </summary>
        public int Year
        ...{
            get ...{ return year; }
        }

        /**//// <summary>
        /// 获取当前日期的农历月份
        /// </summary>
        public int Month
        ...{
            get ...{ return month; }
        }

        /**//// <summary>
        /// 获取当前日期的农历月中天数
        /// </summary>
        public int DayOfMonth
        ...{
            get ...{ return dayOfMonth; }
        }

        /**//// <summary>
        /// 获取当前日期是否为闰月中的日期
        /// </summary>
        public bool IsLeap
        ...{
            get ...{ return isLeap; }
        }

        System.Globalization.ChineseLunisolarCalendar cc;
        /**//// <summary>
        /// 返回指定公历日期的阴历时间
        /// </summary>
        /// <param name="time"></param>
        public ChinaDateTime(DateTime time)
        ...{
            cc = new System.Globalization.ChineseLunisolarCalendar();
           
             if (time > cc.MaxSupportedDateTime || time < cc.MinSupportedDateTime)
                throw new Exception("参数日期时间不在支持的范围内,支持范围:" + cc.MinSupportedDateTime.ToShortDateString()+"到"+cc.MaxSupportedDateTime.ToShortDateString());
            year = cc.GetYear(time);
            month = cc.GetMonth(time);
            dayOfMonth = cc.GetDayOfMonth(time);
            isLeap = cc.IsLeapMonth(year, month);
            if (isLeap) month -= 1;
            this.time = time;

        }

进入讨论组讨论。
更多专题 【深 度 阅 读】 相 关 文 章
    下一页 1 2 
    收藏此文】【 】【打印】【关闭
    相关图文阅读
    频道图文推荐
    健 康 咨 询
    时 尚 咨 询
    巧巧读书宗旨
    相关专题
    讨论组问题推荐
    站内各频道最新更新文档
    站内最新制作专题
    热门关键字导读
    Photoshop教 程照片处理 照片制作 PS快捷键 抠图
    计 算 机 故 障XP系统修复
    艺 术 与 设 计设计 流媒体 设计欣赏 边框
    计 算 机 安 全ARP
    站内频道文章精选
    巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章