给出与FoxPro Week(日期,2,2)相同结果的C#函数是什么
本文关键字:结果 是什么 函数 Week FoxPro 日期 | 更新日期: 2023-09-27 18:28:53
如何在C#中获得与FoxPro函数Week(date, 2, 2)
结果相同的星期日期?
无论使用哪种CCD_ 3,CCD_。
仅仅更改CalendarWeekRule是不够的,还需要更改DayOfWeek。
在VFP中,Week(date,2,2)将星期一指定为一周的第一天。
试试这个:
DateTimeFormatInfo.CurrentInfo.Calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
编辑:看看这个:iso8601一年中的一周在.net
.NET时间段库的Week类支持ISO 8601周格式:
public void CalendarWeekSample()
{
DateTime testDate = new DateTime( 2007, 12, 31 );
// .NET calendar week
TimeCalendar calendar = new TimeCalendar();
Console.WriteLine( "Calendar Week of {0}: {1}", testDate.ToShortDateString(),
new Week( testDate, calendar ).WeekOfYear );
// > Calendar Week of 31.12.2007: 53
// ISO 8601 calendar week
TimeCalendar calendarIso8601 = new TimeCalendar(
new TimeCalendarConfig { YearWeekType = YearWeekType.Iso8601 } );
Console.WriteLine( "ISO 8601 Week of {0}: {1}", testDate.ToShortDateString(),
new Week( testDate, calendarIso8601 ).WeekOfYear );
// > ISO 8601 Week of 31.12.2007: 1
} // CalendarWeekSample