我有2个下拉菜单1,其中年份为1,周数为1。 我想从这些数据中提取日期范围。
所以:
2009年第13周的周数将给出:
星期一23三月2009 2009年3月24日星期二 ...
VB.Net首选,但C#sollution也可以。
编辑: 好吧我想我应该提到这是欧洲约会。
答案 0 :(得分:5)
CultureInfo curCulture = CultureInfo.CurrentCulture;
DateTime targetDate = curCulture.Calendar.AddWeeks(new DateTime([year], 1, 1), [Week]);
DayOfWeek targetWeekDay =
curCulture.Calendar.GetDayOfWeek(targetDate);
DateTime targetBeginningOfWeek = targetDate.AddDays(-1*Convert.ToInt16(targetWeekDay));
targetBeginningOfWeek将包含该周的第一天,添加7天并在该周内休息一天
答案 1 :(得分:3)
尝试使用以下这些功能:
Public Function Week2Date1(ByVal Week2Date2 As Date) As Date
Week2Date1 = DateAdd(DateInterval.Day, -4, Week2Date2)
End Function
Public Function Week2Date2(ByVal WeekNo As Integer) As Date
Week2Date2 = DateSerial(Now.Year, 1, (WeekNo) * 7)
End Function
我使用这些来确定每周星期一和星期五的日期。
其中:
答案 2 :(得分:2)
以下代码获取周数和年份的日期范围。但它用Java编写 希望它有所帮助。
System.out.println("date Range from weekNumber and year but in Java");
System.out.println(); // print a blank line
// get the input from the user
Scanner sc = new Scanner(System.in);
System.out.print("Enter the week : ");
int weekNumber = sc.nextInt();
System.out.print("Enter the Year: ");
int year = sc.nextInt() ;
Calendar cal = Calendar.getInstance();
//cal.setTime(new Date());
cal.set(Calendar.YEAR, year);
cal.set(Calendar.WEEK_OF_YEAR, weekNumber);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(formatter.format(cal.getTime())); // start date
cal.add(Calendar.DAY_OF_WEEK, 6);
System.out.println(formatter.format(cal.getTime())); // end date
答案 3 :(得分:1)
var date = DateTime.MinValue + 2009.Years() + 13.Weeks();
在Codeplex上使用Fluent DateTime项目。