C#顺序万年历自写的求余函数与周位移算法

cs 复制代码
        static int 返回月的天数(int 年, int 月)
        {
            return (月 == 2 ?
                (((年 % 4 == 0 && 年 % 100 > 0) || 年 % 400 == 0) ? 29 : 28) :
                (((月 <= 7 && 月 % 2 > 0) || (月 > 7 && 月 % 2 == 0)) ? 31 : 30));
        }
        static int 返回年总天数(int 年, int 标 = 0)
        {//跳过标年之前,包含标年,因标年1月1日是周1。
            return ((年 -= (标 > 0 ? --标 : 标)) > 0 ? 365 * 年 + ((年 / 4) - (年 / 100) + (年 / 400)) : 0);
        }
        static int 求余(int 数, int 模)
        {
            return (数 - 数 / 模 * 模);
        }
        static void 顺序万年历(int 年, int 月)
        {//计算本年之前的总天数+本月的前月累计+本月1号
            int 天 = 返回年总天数(年 - 1, 1900) + 1, 周 = 月, 填 = 返回月的天数(年, 月 - 1);
            while (--周 > 0) 天 += 返回月的天数(年, 周);
            周 = 填 - 求余(求余(天, 7) + 6, 7);
            Console.WriteLine("一 二 三 四 五 六 天");
            天 = 0;
            while (天 < 42)
            {
                Console.Write((++周).ToString("00 "));
                if (周 >= 填)
                {
                    周 = 0;//转计算本月天数填
                    填 = 返回月的天数(年, 月); 
                }
                if (求余(++天, 7) == 0) Console.WriteLine();
            }
        }

2020年2月

2020年8月

2020年9月

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 农历引用;//工程引用中添加DLL文件

namespace 控制台
{
    class Program
    {
        static int 返回月的天数(int 年, int 月)
        {
            return (月 == 2 ?
                (((年 % 4 == 0 && 年 % 100 > 0) || 年 % 400 == 0) ? 29 : 28) :
                (((月 <= 7 && 月 % 2 > 0) || (月 > 7 && 月 % 2 == 0)) ? 31 : 30));
        }
        static int 返回年总天数(int 年, int 标 = 0)
        {//跳过标年之前,包含标年,因标年1月1日是周1。
            return ((年 -= (标 > 0 ? --标 : 标)) > 0 ? 365 * 年 + ((年 / 4) - (年 / 100) + (年 / 400)) : 0);
        }
        static int 求余(int 数, int 模)
        {
            return (数 - 数 / 模 * 模);
        }
        static void 顺序万年历(int 年, int 月)
        {//计算本年之前的总天数+本月的前月累计+本月1号
            int 天 = 返回年总天数(年 - 1, 1900) + 1, 周 = 月, 填 = 返回月的天数(年, 月 - 1), 侬 = 月 - 1;
            while (--周 > 0) 天 += 返回月的天数(年, 周);
            周 = 填 - 求余(求余(天, 7) + 6, 7);
            Console.WriteLine(系统农历.月历加载(年, 月, DateTime.Now.Day));
            Console.WriteLine("周一浓 周二浓 周三浓 周四浓 周五浓 周六浓 周天浓");
            天 = 0;
            while (天 < 42)
            {
                Console.Write((++周).ToString("00"));
                Console.Write(系统农历.月历加载(年, 侬, 周).Substring(4, 2) + " ");
                if (周 >= 填)
                {
                    周 = 0;//转计算本月天数填
                    ++侬;
                    填 = 返回月的天数(年, 月); 
                }
                if (求余(++天, 7) == 0) Console.WriteLine();
            }
        }
        static void Main(string[] args)
        {

            顺序万年历(DateTime.Now.Year, DateTime.Now.Month);
            Console.WriteLine(".......按任意键退出");
            Console.ReadKey();
        }
    }
}
cs 复制代码
        private void 窗体绘图(object sender, PaintEventArgs e)
        {
            int 天 = 返回年总天数(DateTime.Now.Year - 1, 1900) + 1, 周 = DateTime.Now.Month, 填 = 返回月的天数(DateTime.Now.Year, DateTime.Now.Month - 1), 侬 = DateTime.Now.Month - 1;
            while (--周 > 0) 天 += 返回月的天数(DateTime.Now.Year, 周);
            周 = 填 - 求余(求余(天, 7) + 6, 7);
            string 输出 = 农历引用.系统农历.月历加载(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).Substring(0, 6) + "\n周一浓 周二浓 周三浓 周四浓 周五浓 周六浓 周天浓\n";
            天 = 0;
            while (天 < 42)
            {
                输出 += (++周).ToString("00") + 系统农历.月历加载(DateTime.Now.Year, 侬, 周).Substring(4, 2) + " ";
                if (周 >= 填)
                {
                    周 = 0;//转计算本月天数填
                    ++侬;
                    填 = 返回月的天数(DateTime.Now.Year, DateTime.Now.Month);
                }
                if (求余(++天, 7) == 0) 输出 += "\n";
            }
            if (Convert.ToUInt16(this.WindowState) == 2) e.Graphics.DrawString(输出, new Font("隶书", 14), new SolidBrush(Color.Blue), new PointF(4.0F, this.Height / 2));
        }
相关推荐
q567315237 分钟前
IBM官网新闻爬虫代码示例
开发语言·分布式·爬虫
能工智人小辰8 分钟前
Codeforces Round 509 (Div. 2) C. Coffee Break
c语言·c++·算法
kingmax542120089 分钟前
CCF GESP202503 Grade4-B4263 [GESP202503 四级] 荒地开垦
数据结构·算法
笨笨马甲13 分钟前
附加模块--Qt OpenGL模块功能及架构
开发语言·qt
岁忧14 分钟前
LeetCode 高频 SQL 50 题(基础版)之 【高级字符串函数 / 正则表达式 / 子句】· 上
sql·算法·leetcode
普宁彭于晏31 分钟前
元素水平垂直居中的方法
前端·css·笔记·css3
Tianyanxiao34 分钟前
华为×小鹏战略合作:破局智能驾驶深水区的商业逻辑深度解析
大数据·人工智能·经验分享·华为·金融·数据分析
阿翰1 小时前
自动 GitHub Readme 20 种语言翻译平台 - OpenAiTx 开源免费
c#·.net
eachin_z1 小时前
力扣刷题(第四十九天)
算法·leetcode·职场和发展
m0_637146931 小时前
计算机网络基础总结:TCP/IP 模型、TCP vs UDP、DNS 查询过程
笔记·tcp/ip·计算机网络