如何在某些文化中获取一年中的第几周?

发布于 2024-11-15 04:43:21 字数 1008 浏览 8 评论 0原文

我想获取一年中的第几周(在当前文化中),所以我这样做:

var week = CultureInfo.CurrentCulture.Calendar
           .GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstDay,
                          DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek);

当当前文化为 fa-IR(波斯语)时,日历为 GregorianCalendarweek 值是 24(在波斯语中我们是在第 13 周),

但如果我用 PersianCalendar 测试它,如下所示:

 var calendar = new PersianCalendar();
 var week = calendar
           .GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstDay,
                          DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek);

它给出了正确的答案 (13)。

我检查了文化的日历是波斯语:

var persianCultures = CultureInfo.GetCultures(CultureTypes.AllCultures)
                       .Where(x => x.Calendar is PersianCalendar).ToList();

但没有文化。

但我需要这种文化,因为我认为检查日历是否为公历然后使用波斯语是不好的,如果您有更好的想法或对此有所了解,请告诉我。

(据我所知,公历是旧的,如果我没有错的话,上面发生的事情(使用 Gregorian )是错误的。它应该与波斯历类似。)

I want to get the week of a year (in current culture), so I do:

var week = CultureInfo.CurrentCulture.Calendar
           .GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstDay,
                          DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek);

When current culture is fa-IR (Persian) the calendar is GregorianCalendar and week value is 24 (in Persian we are in the 13th week)

but if I test it with PersianCalendar as below:

 var calendar = new PersianCalendar();
 var week = calendar
           .GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstDay,
                          DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek);

it gives a true answer (13).

I checked that culture's calendar is Persian:

var persianCultures = CultureInfo.GetCultures(CultureTypes.AllCultures)
                       .Where(x => x.Calendar is PersianCalendar).ToList();

but there is no culture.

but I need this culture because I think is not good to check if calendar is Gregorian then use Persian, if you have better idea or know anything about this please let me know it.

(As I know Gregorian calendar is old, and if I'm not wrong what happened above (with Gregorian ) is wrong. it should be similar to Persian calendar.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一梦等七年七年为一梦 2024-11-22 04:43:21

http://www.codeproject.com/KB/dotnet/PersianCulture.aspx

总之,这是 .NET 框架的限制,但可以通过反射来解决此问题。

http://www.codeproject.com/KB/dotnet/PersianCulture.aspx

In summary, it's a limitation of the .NET framework, but a workaround is possible with reflection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文