gpt4 book ai didi

javascript - 使用 C# 从 DatePicker 获取周 ID

转载 作者:行者123 更新时间:2023-11-29 18:50:59 25 4
gpt4 key购买 nike

获取weekid的代码如下

 CultureInfo ciCurr = CultureInfo.CurrentCulture;
int Weekid = ciCurr.Calendar.GetWeekOfYear(dt, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);

When I try for date 31/12/2018 it showed me week Id 53 but in my DatePicker it showed week Id 1

DatePicker 引用图片

enter image description here

问题:

哪个是正确的?

如何使 C# 代码或 jquery 代码的更改相同?

最佳答案

试试这段代码..

来源:https://stackoverflow.com/a/11154921/1997983

 var d = new DateTime(2018, 12, 31);
CultureInfo cul = CultureInfo.CurrentCulture;

var firstDayWeek = cul.Calendar.GetWeekOfYear(
d,
CalendarWeekRule.FirstDay,
DayOfWeek.Monday);

int weekNum = cul.Calendar.GetWeekOfYear(
d,
CalendarWeekRule.FirstDay,
DayOfWeek.Monday);

int year = weekNum == 52 && d.Month == 1 ? d.Year - 1 : d.Year;
Console.WriteLine("Year: {0} Week: {1}", year, weekNum);

根据 ISO-8601,第 53 周返回 1

http://blogs.msdn.com/b/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx

如果您查看 2018 年 12 月 31 日这一周,它将从 12 月 30 日星期六开始。从今年到 2018 年,它将只包含两个日期。30 和 31。其余所有 5 个日期都来自明年,即 2019 年。因此它返回 1 作为周数,根据 ISO-8601 标准这是正确的。

关于javascript - 使用 C# 从 DatePicker 获取周 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51356771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com