/// <summary>
/// 4位数字年周转8位数字年月日 2301->20230101
/// </summary>
public static string GetFirstDayOfWeek(string strYearWeek, System.Globalization.CultureInfo culture)
{
if (strYearWeek.Length != 4) throw new Exception("GetFirstDayOfWeek() strYearWeek 长度必须是4位");
if (strYearWeek.IsNotNumeric()) throw new Exception("GetFirstDayOfWeek() strYearWeek 必须是数字");
int year = ("20" + strYearWeek.Substring(0, 2)).ToInt();
int week = strYearWeek.Substring(2).ToInt();
System.Globalization.Calendar calendar = culture.Calendar;
DateTime firstOfYear = new DateTime(year, 1, 1, calendar);
DateTime targetDay = calendar.AddWeeks(firstOfYear, week - 1);
return targetDay.Year.ToString("0000") + targetDay.Month.ToString("00") + targetDay.Day.ToString("00");
}
4位数字年周转8位数字年月日 2301->20230101
于 2023-02-09 08:18:09 首次发布