如何获得介于数值之间的总周数... [英] How to get total weeks in between to values...

查看:67
本文介绍了如何获得介于数值之间的总周数...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两个下拉值.

第一个下拉列表包含值(3-2008)(3 =第3周,2008 =年份)
第二个下拉菜单包含值(34-2011)(2011年第34周)

我想计算从2008年第3周到2011年第34周的总周数.

在这里,2009年将有53周(我是leap年),2010年将有52周

如何计算这个...?

请给我确切的答案.因为,我在最后一天苦苦挣扎...?

Hi,

I have two dropdown values.

First dropdown contains value (3-2008) (3=3rd week,2008=Year)
Second dropdown contain values (34-2011) (34thweek,2011 year)

I want to calculate total weeks in from 3rd week of 2008 and 34th week of 2011.

Here 2009 will have 53 weeks (i mean leap year)and 2010 will have 52 weeks

How to calculate this...?

pls. give me the exact answer. because, i am struggling last one day...?

推荐答案

此处 [^ ].


希望 [
Hope this[^] might help you.


尝试计算没有实际日期的几周差异几乎是不可能的,并且需要您估计".估算需要进行假设,例如一个日历年中有52周.根据该假设,只剩下一件事情要做-解析组合框中的字符串并进行一些简单的日期数学运算.

Trying to calculate the difference in weeks without having actual dates is pretty much impossible, and requires that you "estimate". Estimation requires assumptions be made, such as there being 52 weeks in a calendar year. Based on that assumption, there''s only one tihing left to do - parse the strings in your combo box and do some simple date math.

string[] parts1 = combo1.SelectedItem.ToString().Split("-");
string[] parts2 = combo2.SelectedItem.ToString().Split("-");

int week1;
int year1;
int week2;
int year2;
int totalWeeks = 0;

if (int.TryParse(parts1[0], out week1) && 
    int.TryParse(parts1[1], out year1) && 
    int.TryParse(parts2[0], out week2) && 
    int.TryParse(parts2[1], out year2))
{
    if (year1 <= year2)
    {
        if (year1 == year2)
        {
            totalWeeks = week2 - week1;
        }
        else
        {
            totalWeeks += (52 - week1) + week2;
            if (year2 - year1 > 1)
            {
                totalWeeks += (52 * year2 - year1);
            }
        }
    }
}



您可能需要调整代码,因为我没有测试就没有输入它.

最后,您确实应该学习如何概念化编程问题.如果您是边缘分析员,这并不困难.



You may need to tweak the code because I didn''t typed it without testing it.

Lastly, you really should learn how to conceptualize your programming problems. This ain''t hard if you are an even marginal analyst.


这篇关于如何获得介于数值之间的总周数...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆