|
■No57547 (shu さん) に返信 > ■No57546 (ちか さん) に返信 > > DateTime dtToday = DateTime.Today; > DateTime dtWeekFirst = dtToday.AddDays(-(int)dtToday.DayOfWeek); > DateTime dtMonday = dtWeekFirst.AddDays((int)DayOfWeek.Monday); > > こんなんでどうでしょう?
Shuさんありがとうございます。 int iWeek = 1; //月の週番号指定
Calendar cal = CultureInfo.CurrentCulture.Calendar; CalendarWeekRule cwr = CultureInfo.CurrentCulture.DateTimeFormat.CalendarWeekRule; DayOfWeek firstDay = DayOfWeek.Sunday;
DateTime DateMonthS = new DateTime(); DateMonthS = DateTime.Parse(”対象年月の1日”); // ”2011/03/01” int weekNumberS = cal.GetWeekOfYear(DateMonthS, cwr, firstDay); if (weekNumberS == 0) { DateMonthS = System.DateTime.Now; }
DateTime DateMonthE = new DateTime(); DateMonthE = new DateTime(DateMonthS.Year, DateMonthS.Month, DateTime.DaysInMonth(DateMonthS.Year, DateMonthS.Month)); int weekNumberE = cal.GetWeekOfYear(DateMonthE, cwr, firstDay);
int MonthWeek = weekNumberE - weekNumberS + 1;
if (iWeek < 1 && MonthWeek < iWeek) { //週番号が範囲外の場合エラーメッセージ break; }
int weekNumber = (iWeek - 1); // 年からの週番号 週番号から対象の週の最初の日付を取るには、、、、 どうしたらよいでしょうか?
|