Reputation: 200
I am using the following line of code in my .vm files. For this particular date I expect the date to be returned to be 12/31/14, but instead it is returning 12/31/15. Does anyone know what could be causing the year to come back wrong?
$date.format('MM/dd/YY', 'Wed Dec 31 07:23:45 CST 2014')
In my tools.xml file, I have added the ComparisonDateTool as seen below:
<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"/>
Upvotes: 1
Views: 884
Reputation: 31648
Change your format to 'MM/dd/yy' (note the lowercase y's)
YY (capital Y) is the 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.
Upvotes: 3