问题描述
我有两个下拉值.
第一个下拉列表包含值(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...?
推荐答案
Dim calendarWeeks As New System.Globalization.GregorianCalendar()
Dim weekCounter As Integer
weekCounter = calendarWeeks.GetWeekOfYear(xxx, Globalization.CalendarWeekRule.FirstFullWeek, DayOfWeek.Sunday)
C#
C#
System.Globalization.GregorianCalendar calendarWeeks = new System.Globalization.GregorianCalendar();
int weekCounter = 0;
weekCounter = calendarWeeks.GetWeekOfYear(xxx, Globalization.CalendarWeekRule.FirstFullWeek, DayOfWeek.Sunday);
注意:我假设您已经有一个代码来正确获取dateformat?请用日期格式的值替换 xxx .你应该工作.
您的weekCounter应该包含一年中的星期数.
Note: I assume that you already have a code to get the dateformat right? please replace the xxx with the value you have in a date format. That you should work.
your weekCounter should contain the number of week in a year.
这篇关于计算从2008年第3周到2011年第34周的总周数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!