2009-03-29 28 views
0

私は週番号1と年数2の2つのドロップダウンを持っています。 このデータから日付範囲を抽出します。だから、日付範囲は週番号+年

Weeknumberは13年の2009年には与える:

月曜日2009年3月23日 火曜日2009年3月24日 ...

VB.Net好ましいが、C#のsollutionもokです。

編集: 私はこれがヨーロッパの日付のために言及すべきだったと思います。

答えて

1
var date = DateTime.MinValue + 2009.Years() + 13.Weeks(); 

で一日の残りの部分を取得します。

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日を追加して、CodePlexに上Fluent DateTimeプロジェクトを使用して、その週

+0

以前のものは不完全でした更新されたものは役に立ちました –

+0

これは素晴らしい、ありがとう! – mkchandler

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 

私は月曜日と毎週数の金曜日の日付を決定するためにこれらを使用しています。

:機能Week2Date1の機能Week2Date2上

  • は、週番号の金曜日を返し、
  • はWeek2Date2で​​返される日付の値から、週番号の月曜日が返されます。
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