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));
        }
相关推荐
焦耳加热3 小时前
阿德莱德大学Nat. Commun.:盐模板策略实现废弃塑料到单原子催化剂的高值转化,推动环境与能源催化应用
人工智能·算法·机器学习·能源·材料工程
CodeCraft Studio3 小时前
PDF处理控件Aspose.PDF教程:使用 Python 将 PDF 转换为 Base64
开发语言·python·pdf·base64·aspose·aspose.pdf
零点零一3 小时前
VS+QT的编程开发工作:关于QT VS tools的使用 qt的官方帮助
开发语言·qt
wan5555cn3 小时前
多张图片生成视频模型技术深度解析
人工智能·笔记·深度学习·算法·音视频
u6063 小时前
常用排序算法核心知识点梳理
算法·排序
雁于飞5 小时前
vscode中使用git、githup的基操
笔记·git·vscode·学习·elasticsearch·gitee·github
rannn_1115 小时前
【Javaweb学习|实训总结|Week1】html基础,CSS(选择器、常用样式、盒子模型、弹性盒布局、CSS定位、动画),js(基本类型、运算符典例)
css·笔记·学习·html
lingchen19065 小时前
MATLAB的数值计算(三)曲线拟合与插值
开发语言·matlab
Ro Jace5 小时前
心灵笔记:第一性原理学习与实践
笔记
gb42152875 小时前
java中将租户ID包装为JSQLParser的StringValue表达式对象,JSQLParser指的是?
java·开发语言·python