gpt4 book ai didi

Java/Apache Velocity date.format 给出错误的年份

转载 作者:行者123 更新时间:2023-11-29 05:16:30 25 4
gpt4 key购买 nike

我在我的 .vm 文件中使用了以下代码行。对于这个特定的日期,我希望返回的日期是 12/31/14,但它返回的是 12/31/15。有谁知道可能导致年份错误的原因是什么?

$date.format('MM/dd/YY', 'Wed Dec 31 07:23:45 CST 2014')

在我的 tools.xml 文件中,我添加了如下所示的 ComparisonDateTool:

<tool class="org.apache.velocity.tools.generic.ComparisonDateTool"
format="MM/dd/yyyy H:m:s" depth="1" skip="month,week"
bundle="org.apache.velocity.tools.generic.times" timezone="CST"/>

最佳答案

将格式更改为“MM/dd/yy”(注意小写的 y)

YY(大写 Y)是 Week Year

The first week of a calendar year is the earliest seven day period starting on getFirstDayOfWeek() that contains at least getMinimalDaysInFirstWeek() days from that year. It thus depends on the values of getMinimalDaysInFirstWeek(), getFirstDayOfWeek(), and the day of the week of January 1. Weeks between week 1 of one year and week 1 of the following year (exclusive) are numbered sequentially from 2 to 52 or 53 (except for year(s) involved in the Julian-Gregorian transition).

....

All weeks between the first and last weeks (inclusive) have the same week year value. Therefore, the first and last days of a week year may have different calendar year values. ... For example, January 1, 1998 is a Thursday. If getFirstDayOfWeek() is MONDAY and getMinimalDaysInFirstWeek() is 4 (ISO 8601 standard compatible setting), then week 1 of 1998 starts on December 29, 1997, and ends on January 4, 1998. The week year is 1998 for the last three days of calendar year 1997. If, however, getFirstDayOfWeek() is SUNDAY, then week 1 of 1998 starts on January 4, 1998, and ends on January 10, 1998; the first three days of 1998 then are part of week 53 of 1997 and their week year is 1997.

关于Java/Apache Velocity date.format 给出错误的年份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26347231/

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