不明智地分割一周 [英] split the week no year wise
本文介绍了不明智地分割一周的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想每年不分割一周.例如,如果2006年有52周,它将显示1到52.如果2007年又有53周,它将像这样拆分1到53.
现在,我将显示所有星期,不对差异进行拆分.年.
代码如下.
--------------
Hi,
I want to split the week no year wise. for example if 2006 has 52 weeks it will display 1 to 52. if 2007 has 53 weeks again it will split 1 to 53 like that.
now, i am displaying all the weeks without split for the diff. year.
Code is below.
--------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'' Assumes that week range is from Sunday - Saturday
Dim FromYr As Integer = "2006"
Dim ToYear As Integer = "2015"
Dim firstDayOfYear As New DateTime(FromYr, 1, 1)
Dim lastDayOfYear As New DateTime(ToYear, 12, 31)
Dim weekNumber As Integer = 0
Dim weekList As New List(Of String)()
Dim tempDate As DateTime = firstDayOfYear
Dim tempString As String = String.Empty
While tempDate <= lastDayOfYear
weekNumber += 1
tempString = weekNumber.ToString() & " | "
tempString += tempDate.ToShortDateString() & " - "
tempDate = GetLastDayOfWeek(tempDate, lastDayOfYear)
tempString += tempDate.ToShortDateString()
weekList.Add(tempString)
tempDate = tempDate.AddDays(1)
End While
drpWeeknos.DataSource = weekList
drpWeeknos.DataBind()
End Sub
Private Function GetLastDayOfWeek(ByVal firstDayOfWeek As DateTime, ByVal lastDayOfYear As DateTime) As DateTime
Dim lastDayOfWeek As DateTime = firstDayOfWeek
If firstDayOfWeek.DayOfWeek = DayOfWeek.Monday Then
lastDayOfWeek = firstDayOfWeek.AddDays(6)
End If
If firstDayOfWeek.DayOfWeek = DayOfWeek.Tuesday Then
lastDayOfWeek = firstDayOfWeek.AddDays(5)
End If
If firstDayOfWeek.DayOfWeek = DayOfWeek.Wednesday Then
lastDayOfWeek = firstDayOfWeek.AddDays(4)
End If
If firstDayOfWeek.DayOfWeek = DayOfWeek.Thursday Then
lastDayOfWeek = firstDayOfWeek.AddDays(3)
End If
If firstDayOfWeek.DayOfWeek = DayOfWeek.Friday Then
lastDayOfWeek = firstDayOfWeek.AddDays(2)
End If
If firstDayOfWeek.DayOfWeek = DayOfWeek.Saturday Then
lastDayOfWeek = firstDayOfWeek.AddDays(1)
End If
If firstDayOfWeek.DayOfWeek = DayOfWeek.Sunday Then
lastDayOfWeek = firstDayOfWeek
End If
If lastDayOfWeek > lastDayOfYear Then
lastDayOfWeek = lastDayOfYear
End If
Return lastDayOfWeek
End Function
请帮助.下拉列表显示为每年都不明智.
问候,
Ganesh.S
Pls. help. Dropdown display as week no wise for every year.
Regards,
Ganesh.S
推荐答案
似乎是您以不同的方式发布了相同的问题.
在这里看看我的解决方案
我想获取所有星期列表 [ ^ ]
您可以对一年中的第一天到一年中的最后一天使用相同的方法.差异将给出一年中的工作周数.
Calendar.Getweekofyear是方法.
Seems to be you are posting the same question in different ways.
Take a look at my solution here
i want to get all the list of week[^]
You can use the same method with first day of the year to last day of the year. The diff will give the number of workweeks in an year.
Calendar.Getweekofyear is the method.
我在这里发布了一个详细的示例,说明了如何找到两个日期之间的星期,这是您在下面的另一个问题: ^ ].
最好的问候,
--MRB
I posted an elaborated example on how to find the weeks between two dates to your other question here: i want to get all the list of week[^].
Best Regards,
--MRB
这篇关于不明智地分割一周的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文