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

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - 骑着夕阳看着猪

asp.net mvc 中hmtl.xxxx是否使用<%=... %> 高版本(vs2008)如何打开低版本解决方案和项目(vs2003、vs2005的项目) 序列化和反序列化 sql 根据父节点查找所有子节点 用jquery实现学校的校历 一步一步学jquery UI 1.72 之datepicker - 骑着夕阳看着猪 c# 日期相减 如何使图片在div里上下居中 - 骑着夕阳看着猪 - 博客园 实现qq邮箱换肤(第二季 ) - 骑着夕阳看着猪 - 博客园 实现qq邮箱换肤(第一季 ) 获取元素和鼠标的位置(兼容IE6.0,IE7.0,IE8.0,FireFox2.0,FireFox3.5,Opera) img src='' 为空引发的问题 - 骑着夕阳看着猪 如何清除html图片缓存 - 骑着夕阳看着猪 - 博客园 关于 wcf揭秘 第四章代码运行错误 - 骑着夕阳看着猪 配置SQL Server2005以允许远程访问 SQL Server2005还原数据库详细 初试ajax基础 实现控件的随意拖动 BindingManagerBase的应用
显示日期是当前区间第几周? - 骑着夕阳看着猪 - 博客园
骑着夕阳看着猪 · 2009-12-24 · via 博客园 - 骑着夕阳看着猪

代码

        /// <summary>
        
/// 显示日期是当前区间第几周?
         
/// </summary>
        
/// <param name="day">当前日期</param>
        
/// <param name="datespanGuid"></param>
        
/// <returns></returns>
        public int GetCurrentWeek(DateTime day, Guid datespanGuid) 
        {
            CDateSpan span 
= db.CDateSpan.SingleOrDefault(u => u.DateSpanGuid == datespanGuid);
            
if (span != null && span.EndTime.Subtract(day).Days >= 0 && day.Subtract(span.BeginTime).Days >= 0)
            {
                
int currentWeek = 1;//计算出第一周周末(星期六)的日期
                DateTime beginSaturday = span.BeginTime.Add(new TimeSpan(span.Offset, 000));    //span.BeginTime-span.Offset:起始周开始计算的时间

                
int saturdaySpan = 6 - (int)(beginSaturday.DayOfWeek);    //这天离周末还有几天

                beginSaturday 
= beginSaturday.Add(new TimeSpan(saturdaySpan, 000)); // 周末的日期//
                int days = day.Subtract(beginSaturday).Days;
                
if (days > 0
                {
                    currentWeek 
+= days / 7 + 1;
                }
               
                
return currentWeek;
            }
            
else 
            {
                
return -1;//区间不存在或者日期不在区间中
            }
        }