惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - ever

2007 新的生活 当爱 八荣八耻 最IN的50句英语口头禅! 宁静 佛语智慧 好心分手 认识 凌晨 新的想法 今天的想法 头疼的事 搬家啦 北京,北京 不能承受之轻 love 程序员的.NET时代(转载) 离职前夕 困惑
C#实现的根据年月日计算星期几的函数 (转载)
ever · 2006-05-08 · via 博客园 - ever

算法如下: 
基姆拉尔森计算公式
W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7

  在公式中d表示日期中的日数,m表示月份数,y表示年数。

注意:在公式中有个与其他公式不同的地方:

 把一月和二月看成是上一年的十三月和十四月,例:如果是2004-1-10则换算成:2003-13-10来代入公式计算。

代码如下:
 //y-年,m-月,d-日期
  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 7: weekstr="星期日"; break;
   }

          return weekstr;
  }

调用方法:
Label2.Text=CaculateWeekDay(2004,12,9);