increase date based on ${copyrightYear}
I need your help in creating a script on Freemarker with a list of year options based on ${copyrightYear} as a base year. I will use this on credit card expiration options that will have an output like this.
<option value="" name="">Year</option>
<option value="2011">2011</option>
<option value="2012">2012&开发者_StackOverflow中文版lt;/option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
...until 2021
2011 should be ${copyrightYear} and it will increment 10 times until it reaches the year 2021. I want this to be automated every year. Any help from you guys will be much appreciated.Thanks!
Well, assuming your model is setup to use static methods. This should work,
<#setting number_format="##">
<#assign currentYear = statics["java.util.Calendar"].getInstance().getTime()?string("yyyy")?number>
<option value="" name="">Year</option>
<#list currentYear..(currentYear + 10) as year>
<option value="${year}">${year}</option>
</#list>
There are several ways to get the current year. If you need to, make sure you get the current year in the correct locale.
Edit 1:
As Chaquotay graciously noted, with FreeMarker 2.3.17 .now can be used to get current time instead of the static call to Calendar.
精彩评论