两次之间的周数 [英] Count of Week between

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

问题描述

大家好,

我必须下拉列表.每个下拉列表都包含星期和年份的值(例如1-2006).我要计算周数,并且要在vb.net的文本框中显示该计数,同时页面加载下拉列表应自动显示当前的周和年. (例如,本周是第27周和2011年.)

因此,在页面加载时,两个下拉列表均应显示27-2011.

怎么做.

1)我不希望统计在下拉菜单之间的周数.(1-2006至5-2007)1和5是对应年份的周.

2)默认情况下,我要在页面加载时的下拉列表中显示当前星期.

我的周从星期一到星期日开始.

预先感谢您的帮助.

问候,
Ganesh.S

Hi All,

I have to dropdown. Each dropdown contain week and year values (Ex.1-2006). I want to count the weeks and the count want to display in textboxes in vb.net and also while pageload dropdown should automatically display the current week and year. (Ex.this week is 27th week and 2011 year.)

So both dropdown should display 27-2011 while page load.

How to do this.

1) I want to count no of weeks in between seleted dropdown.(1-2006 to 5-2007) 1 and 5 is the week for the corresponding year.

2) I want to display the current week is by default in the dropdown while page load.

My weeks starts from Monday to sunday.

Thanks in advance for the help.

Regards,
Ganesh.S

推荐答案

我不知道为什么我要回答这个问题! :doh:
你甚至尝试过吗?

I don''t know why I am answering this!! :doh:
Did you even try?

    Dim result as Integer
    Dim s1 As String = "5-2007"
    Dim s2 As String = "42-2011"
    If (Convert.ToInt16(s2.Split("-")(1)) < Convert.ToInt16(s1.Split("-")(1))) _
    OrElse ((Convert.ToInt16(s2.Split("-")(1)) = Convert.ToInt16(s1.Split("-")(1))) And (Convert.ToInt16(s2.Split("-")(0)) <= Convert.ToInt16(s1.Split("-")(0)))) Then
      ''error
    ElseIf (Convert.ToInt16(s2.Split("-")(1)) = Convert.ToInt16(s1.Split("-")(1))) Then
      result=MsgBox(Convert.ToInt16(s2.Split("-")(0)) - Convert.ToInt16(s1.Split("-")(0)))
    Else
      Dim weeks1 As Integer = (52 - Convert.ToInt16(s1.Split("-")(0)))
      Dim weeks2 As Integer = (Convert.ToInt16(s2.Split("-")(0)))
      result=(52 * (Convert.ToInt16(s2.Split("-")(1)) - Convert.ToInt16(s1.Split("-")(1)) - 1) + weeks1 + weeks2)
    End If
''result is the weeks





Dim dfi As Globalization.DateTimeFormatInfo = Globalization.DateTimeFormatInfo.CurrentInfo
Dim cal As Globalization.Calendar = dfi.Calendar
''Your current value should be
''(cal.GetWeekOfYear(Today, Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday) & "-" & Today.Year)


这是逻辑,为什么您需要帮助.
This is logic, why do u need help.


您也许可以使用.NET的时间段库 [
You may be able to use something from Time Period Library for .NET[^]. You would likely have to modify something here, but it could help you along the way.


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

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