I need to get the current week of the year based on a string date.
E.g. 07.03.2023
→ Week 10 of 2023
.
In the docs I found many helpers, but none for the week of the year.
<#assign aDate = theDate?date>
<!-- All kind of day of the week, month, year etc, -->
${aDate?string["EEE, MMM d, ''yy"]}
<!-- How to get the week of the year? -->
How could I get the week of the year of a date using just the FreeMarker template?
FreeMarker uses the Java simple date format patterns to format dates. You can use the w
pattern to get the "week in year". So you can simply do:
Current week number: ${.now?string['w']}
As Basil pointed out, you want to make sure you are using the right locale. There are several ways to set the locale in FreeMarker.