Dateformat ww returns 错误的一周

Dateformat ww returns wrong week of year

有人可以解释为什么得到这个日期的星期 returns 1 而不是 53 吗?我如何在这个日期将 coldfusion 达到 return 53?

<cfscript>
    Date1 = "{ts '2019-12-30  12:00:00'}";
    dateformat= DateFormat(Date1)
    week= DateFormat(Date1,"ww")
    writeOutput("Week: " & week & "<br/>")
</cfscript>

查看冷聚变fiddle:https://cffiddle.org/app/file?filepath=ab0d50c0-d268-4769-b5eb-a16a8fca985a/dc6aebb2-76a8-4485-a5eb-e9eb17b293cb/9e6e8b2c-f570-45be-88a1-49db39f8c69b.cfm

您可以使用 week(Date) 而不是尝试 dateformat

我不确定为什么 dateformat 将 2019 年的最后一周作为 2020 年的第一周。很可能 dateformat 并不是为了处理这些细微的逻辑而设计的。由于 Week 函数必须专门为此目的而设计,因此使用它是明智的。如果我能找到任何具体的建议 dateformat 问题的原因,我会更新答案。

根据@Agreax 的评论更新:

Week() 使用 Adob​​e 的内部逻辑。 DateFormat() 使用 java 的 SimpleDateFormat class 其中 ".. depends on the values of getMinimalDaysInFirstWeek(), getFirstDayOfWeek(), and the day of the week of January 1.."。使用默认设置,12/30/2019 被视为 2020 年第一周的一部分。