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>
您可以使用 week(Date)
而不是尝试 dateformat
。
我不确定为什么 dateformat
将 2019 年的最后一周作为 2020 年的第一周。很可能 dateformat
并不是为了处理这些细微的逻辑而设计的。由于 Week
函数必须专门为此目的而设计,因此使用它是明智的。如果我能找到任何具体的建议 dateformat
问题的原因,我会更新答案。
根据@Agreax 的评论更新:
Week()
使用 Adobe 的内部逻辑。 DateFormat()
使用 java 的 SimpleDateFormat
class 其中 ".. depends on the values of getMinimalDaysInFirstWeek(), getFirstDayOfWeek(), and the day of the week of January 1.."。使用默认设置,12/30/2019 被视为 2020 年第一周的一部分。
有人可以解释为什么得到这个日期的星期 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>
您可以使用 week(Date)
而不是尝试 dateformat
。
我不确定为什么 dateformat
将 2019 年的最后一周作为 2020 年的第一周。很可能 dateformat
并不是为了处理这些细微的逻辑而设计的。由于 Week
函数必须专门为此目的而设计,因此使用它是明智的。如果我能找到任何具体的建议 dateformat
问题的原因,我会更新答案。
根据@Agreax 的评论更新:
Week()
使用 Adobe 的内部逻辑。 DateFormat()
使用 java 的 SimpleDateFormat
class 其中 ".. depends on the values of getMinimalDaysInFirstWeek(), getFirstDayOfWeek(), and the day of the week of January 1.."。使用默认设置,12/30/2019 被视为 2020 年第一周的一部分。