Apoya a Time.now: Únete a nuestro Plan Premium ¡para una experiencia sin anuncios! Apóyanos: ¡Hazte Premium sin anuncios!

Week numbers in .NET (Legacy)

To get the current ISO 8601 week number in .NET (Legacy), use the following code snippet:

CultureInfo.CurrentCulture.Calendar.GetWeekOfYear( DateTime.Now, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday );

* Ensure your system or application regional settings are set to follow ISO 8601 standards (weeks start on Monday) if the output varies.

Instrucciones paso a paso

  1. Get the current culture's calendar via CultureInfo.CurrentCulture.Calendar.
  2. Call GetWeekOfYear with CalendarWeekRule.FirstFourDayWeek and DayOfWeek.Monday.
  3. The parameters approximate ISO 8601 numbering on legacy .NET Framework.

Conviene saber

This legacy approach can return week 53 for the Monday-Wednesday before an ISO week 1 (a documented .NET Framework quirk). If you can target .NET Core 3.0+, use System.Globalization.ISOWeek instead.