首页 > 学院 > 开发设计 > 正文

根据年月日算出当前日期是星期几

2019-11-14 16:52:12
字体:
来源:转载
供稿:网友
   /// <summary>        /// 根据年月日计算星期几        /// </summary>        /// <param name="y">年</param>        /// <param name="m">月</param>        /// <param name="d">日</param>        /// <returns></returns>        public static string CaculateWeekDay(int y, int m, int d)        {            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 1: weekstr = "星期一"; break;                case 2: weekstr = "星期二"; break;                case 3: weekstr = "星期三"; break;                case 4: weekstr = "星期四"; break;                case 5: weekstr = "星期五"; break;                case 6: weekstr = "星期六"; break;                case 0: weekstr = "星期日"; break;            }            return weekstr;        }

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表