WindowsPhone 在 根据公历 获取月球日期数据「建议收藏」

WindowsPhone 在 根据公历 获取月球日期数据

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

WindowsPhone 在 根据公历 获取月球日期数据

WindowsPhone 在 它们的定义 类,根据公历 获取月球日期数据

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ChineseCalendar
{
    /// <summary>
    /// 中国农历
    /// </summary>
    public static class ChineseDate
    {
        #region 日历数据
        /// <summary>
        /// int[] CalendarData
        /// </summary>
        static int[] CalendarData = new int[] {
                    0x41A95, 0xD4A, 0xDA5, 0x20B55, 0x56A, 0x7155B,
                    0x25D, 0x92D, 0x5192B, 0xA95, 0xB4A, 0x416AA, 0xAD5,
                    0x90AB5, 0x4BA, 0xA5B, 0x60A57, 0x52B, 0xA93, 0x40E95 };


        /// <summary>
        /// int[] madd
        /// </summary>
        static int[] madd = new int[] { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };


        static String numString = "一二三四五六七八九十";
        static String monString = "正二三四五六七八九十冬腊";
        static String[] run = new String[] { "闰正", "闰二", "闰三", "闰四", "闰五", "闰六", "闰七", "闰八", "闰九", "闰十", "闰冬", "闰腊" };
        static String cDateString = String.Empty;
        static int cYear, cMonth, cDay, cHour;
        static String holiday = String.Empty;
        #endregion


        #region 节日数据
        /// <summary>
        /// 农历节日数据
        /// </summary>
        static String[] NLHoliday = new String[] { 
                "正月初一 春节",
                "正月十五 元宵节",
                "二月初二 龙抬头",
                "五月初五 端午节",
                "七月初七 七夕",
                "七月十五 中元节",
                "八月十五 中秋节",
                "九月初九 重阳节",
                "腊月初八 腊八节",
                "腊月廿三 小年",
                "腊月三十 除夕"
        };


        //公历节日 表示放假日
        static String[] GLHoliday = new String[] {
                "0101 元旦",
                "0214 情人节",
                "0308 妇女节",
                "0312 植树节",
                "0401 愚人节",
                "0422 地球日",
                "0501 劳动节",
                "0504 青年节",
                "0531 无烟日",
                "0601 儿童节",
                "0606 爱眼日",
                "0701 建党日",
                "0707 抗战纪念日",
                "0801 建军节",
                "0910 教师节",
                "0918 九一八事变",
                "1001 国庆节",
                "1031 万圣节",
                "1111 光棍节",
                "1201 艾滋病日",
                "1213 南京大屠杀纪念日",
                "1224 平安夜",
                "1225 圣诞节"
        };
        #endregion


        #region 计算方法
        /// <summary>
        /// int GetBit
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        private static int GetBit(int m, int n)
        {
            return (m >> n) & 1;
        }




        /// <summary>
        /// void e2c
        /// </summary>
        /// <param name="dt">公历时间</param>
        private static void e2c(DateTime dt)
        {
            bool isEnd = false;
            int total, m, n, k, tmp = dt.Year;

            if (tmp < 1900) tmp += 1900;

            total = (tmp - 2001) * 365
                  + (int)Math.Floor((Double)(tmp - 2001) / 4)
                  + madd[dt.Month - 1]
                  + dt.Day
                  - 23;

            if (dt.Year % 4 == 0 && dt.Month > 2)
                total++;

            for (m = 0; ; m++)
            {
                k = (CalendarData[m] < 0xfff) ?

11 : 12;                for (n = k; n >= 0; n--)                {                    if (total <= 29 + GetBit(CalendarData[m], n))                    {                        isEnd = true;                        break;                    }                    total = total - 29 - GetBit(CalendarData[m], n);                }                if (isEnd) break;            }            cYear = 2001 + m;            cMonth = k - n + 1;            cDay = total;            if (k == 12)            {                if (cMonth == (int)Math.Floor((double)(CalendarData[m] / 0x10000) + 1))                    cMonth = 1 - cMonth;                if (cMonth > (int)Math.Floor((double)(CalendarData[m] / 0x10000) + 1))                    cMonth--;            }            cHour = (int)Math.Floor((double)((dt.Hour + 3) / 2));        }        /// <summary>        /// void GetcDateString()        /// </summary>        private static void GetcDateString()        {            String tmp = String.Empty;            if (cMonth < 1)            {                tmp += "闰";                tmp += monString[-cMonth - 1];            }            else tmp += monString[cMonth - 1] + "月";            if (cDay <= 10) tmp += "初";            else if (cDay < 20) tmp += "十";            else if (cDay == 20) tmp += "二十";            else if (cDay < 30) tmp += "廿";            else tmp += "三十";            if (cDay % 10 != 0 || cDay == 10)                tmp += numString[Math.Abs(cDay - 1) % 10];            cDateString = tmp;        }        /// <summary>        /// 获取相应日期的节日数据        /// </summary>        /// <param name="dt"></param>        /// <param name="strDate"></param>        private static void getHoliday(DateTime dt, String strDate)        {            //获取农历节日            String strNLHoliday = String.Empty;            if (strDate == "正月")                strNLHoliday = "春节";            else            {                for (int i = 0, len = NLHoliday.Length; i < len; i++)                {                    if (NLHoliday[i].ToString().Contains(strDate))                    {                        strNLHoliday = NLHoliday[i].ToString().Split(' ')[1];                        break;                    }                }            }            //获取公历节日            String strGLHoliday = String.Empty;            for (int i = 0, len = GLHoliday.Length; i < len; i++)            {                if (GLHoliday[i].ToString().Contains(dt.ToString("MMdd")))                {                    strGLHoliday = GLHoliday[i].ToString().Split(' ')[1];                    break;                }            }            //返回结果            if (!String.IsNullOrEmpty(strNLHoliday) && !String.IsNullOrEmpty(strGLHoliday))                holiday = (strNLHoliday + strGLHoliday).Replace("节", "");            else if (!String.IsNullOrEmpty(strNLHoliday))                holiday = strNLHoliday;            else if (!String.IsNullOrEmpty(strGLHoliday))                holiday = strGLHoliday;            else holiday = String.Empty;        }        #region 农历年        /// <summary>        /// 十天干        /// </summary>        private static string[] tiangan = { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };        /// <summary>        /// 十二地支        /// </summary>        private static string[] dizhi = { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };        /// <summary>        /// 十二生肖        /// </summary>        private static string[] shengxiao = { "鼠", "牛", "虎", "免", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };        /// <summary>        /// 返回农历天干地支年         /// </summary>        /// <param name="year">农历年</param>        /// <returns></returns>        private static string GetLunisolarYear(int year)        {            int tgIndex = (year - 1900 + 36) % 10;            int dzIndex = (year - 1900 + 36) % 12;            return string.Concat(tiangan[tgIndex], dizhi[dzIndex], "【", shengxiao[dzIndex], "】");        }        #endregion        #endregion        #region 调用方法        /// <summary>        /// 获取农历日期(格式 dd)        /// </summary>        /// <param name="dt"></param>        /// <returns></returns>        public static String getNLDate(DateTime dt)        {            e2c(dt);            GetcDateString();            //获取节日            getHoliday(dt, cDateString);            if (cDateString.Contains("初一"))                cDateString = cDateString.Replace("初一", "");            else                cDateString = cDateString.Substring(cDateString.IndexOf("月") + 1);            for (int i = 0, len = run.Length; i < len; i++)            {                if (cDateString.Contains(run[i]))                {                    cDateString = cDateString.Replace(run[i], "");                    if (String.IsNullOrEmpty(cDateString))                        cDateString = run[i];                    break;                }            }            return cDateString;        }        /// <summary>        /// 获取农历日期(格式 年月日完整日期)        /// </summary>        /// <param name="dt"></param>        /// <returns></returns>        public static String getNLDateTime(DateTime dt)        {            //农历月            getNLDate(dt);            return GetLunisolarYear(dt.Year) + "年" + cDateString;        }        /// <summary>        /// 获取节日数据        /// </summary>        /// <returns></returns>        public static String getHoliday()        {            return holiday;        }        #endregion    }}

备注:此类 是更依据网上的 javascript 改编而来。

            经过測试,当输入的公历 年 小于 2001 年 获取的农历日期数据就会有误。

            而且 当 输入的年 大于 2040 年后 获取的农历数据也会有误!

          希望有人可以完好。谢谢。

效果图:

          WindowsPhone 在 根据公历 获取月球日期数据「建议收藏」

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116725.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • iPhone手机屏幕尺寸分辨率一览

    iPhone手机屏幕尺寸分辨率一览机型物理像素逻辑像素规格对角线iPhone12ProMax1284*2778px428*926pt@3×6.7英寸iPhone12Pro1170*2532px390*844pt@3×6.1英寸iPhone121170*2532px390*844pt@3×6.1英寸iPhone12mini1080*2340px360*780pt@3×5.4英寸iPhone11ProMax1242*2688px414*8…

    2022年5月14日
    58
  • 苹果x充电慢是什么原因_手机资讯:为什么 iPhone 充电从 99% 到 100% 时特别慢是电池故障吗…

    如今使用IT数码设备的小伙伴们是越来越多了,那么IT数码设备当中是有很多知识的,这些知识很多小伙伴一般都是不知道的,就好比最近就有很多小伙伴们想要知道为什么iPhone充电从99%到100%时特别慢是电池故障吗,那么既然现在大家对于为什么iPhone充电从99%到100%时特别慢是电池故障吗都感兴趣,小编就来给大家分享下关于为什么iPhone充电从99%到100%…

    2022年4月7日
    260
  • java开发常用软件下载地址及教程。

    java开发常用软件下载地址及教程。本文以Windows64位为例,如有mac或Linux系统的请自行选择对应系统进行下载一.JDK1.官网下载地址(最新版本):http://www.oracle.com/technetwork/java/javase/downloads/index.html2.以前的所有版本(包括JDK1.8或JDK1.7等):http://www.oracle.com/technetwork/java/j…

    2022年7月8日
    22
  • java spel_SPEL表达式注入-入门篇

    java spel_SPEL表达式注入-入门篇SpringExpressionLanguage(简称SpEL)是一种强大的表达式语言,支持在运行时查询和操作对象图。语言语法类似于UnifiedEL,但提供了额外的功能,特别是方法调用和基本的字符串模板功能。同时因为SpEL是以API接口的形式创建的,所以允许将其集成到其他应用程序和框架中。个人理解就是Spring框架中的一种语言表达式,类似于Struts2中的OGNL的东西。一个最基础的…

    2022年9月11日
    1
  • mongodb百亿数据存储(mysql数据库并发量)

    3 过程分析与测试3.1 GridFS概述由于MongoDB中的Bson对象大小是有限制的,在1.7版本以前单个Bson对象最大容量为4M,1.7版本以后单个Bson对象最大容量为16M[5]。对于一般的文件存储,单个对象的4到16M的存储容量能够满足需求,但无法满足对于一些大文件的存储,如高清图片、设计图纸、视频等,因此在海量数据存储方面,MongoDB提供了内置的GridFS,

    2022年4月14日
    1.1K
  • pycharm 断点调试失效[通俗易懂]

    pycharm 断点调试失效[通俗易懂]pycharm断点调试失效,再第一行执行代码打了断点,Debug之后还是全部运行,但是在其他行打断点就可以正常调试。试了好多其他博主写的方法,都没用,最后发现是因为第一行是注释,把第一行的注释移到下面或第一行可执行代码的后面就可以调试了…

    2025年7月23日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号