zoukankan      html  css  js  c++  java
  • C#实现的根据年月日计算星期几的函数(修正版)测试过,绝对能用!


              网络上好多都是直接转载的,今天我测试一下,有点问题!稍微改了以下,请大家多多指教

            public string WeekDayNoMsg()
            {
                int y= int.Parse(DateTime.Now.ToString("yyyy"));
                int m=int.Parse(DateTime.Now.ToString("MM"));
                int d = int.Parse(DateTime.Now.ToString("dd"));
                if (m == 1) m = 13;
                if (m == 2) m = 14;
                int week = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
                string weekstr = "";
                 switch (week)
                {
                    case 0: weekstr = "星期一"; break;
                    case 1: weekstr = "星期二"; break;
                    case 2: weekstr = "星期三"; break;
                    case 3: weekstr = "星期四"; break;
                    case 4: weekstr = "星期五"; break;
                    case 5: weekstr = "星期六"; break;
                    case 6: weekstr = "星期日"; break;
                }

                return weekstr;
            }

  • 相关阅读:
    linux基础名词
    计算机基础
    c++ 构造函数
    c++ stdafx.h、targetver.h文件
    centos7初步命令
    mysql 操作表的语句
    后台返回API数据格式
    nginx相关知识
    js复制内容到剪贴板格式化粘贴到excel中
    PHP开启错误提示
  • 原文地址:https://www.cnblogs.com/kaixinmenghuan/p/1869798.html
Copyright © 2011-2022 走看看