how can i create an date object in ftl. the below code isn't helping me
<#assign now2 = new java.util.Date()>
can anyone provide me a link on tutorial for working with dates in ftl the programmer guide of ftl is not clear
how can i create an date object in ftl. the below code isn't helping me
<#assign now2 = new java.util.Date()>
can anyone provide me a link on tutorial for working with dates in ftl the programmer guide of ftl is not clear
A new date with what value? If you need the current time, you can use the .now
variable. Otherwise you can use something like ${'2014-01-05T23:30:00'?datetime.iso}
.
This isn't the answer you're looking for, but it may be useful anyway.
You probably ought to ask yourself why you want to create a date within the FTL template. FTL is powerful, but its core strength is controlling the presentation of data from another source. In the case where I've used FTL, the source of the data is generally a model object produced by the controller object, and the relationship of the FTL view to the others is managed through Spring MVC. In a design like that, getting the current date into the FTL view is as simple as adding a model attribute:
model.addAttribute("date", new java.util.Date());
FTL then has facilities for rendering the date in configurable fashion. This post talks about how to configure date time rendering within FTL, as well as how to integrate JodaTime into Freemarker so that it can be rendered as well.
Following is the example on how can we create date object
example1 :
<#assign objectConstructor2 = "freemarker.template.utility.ObjectConstructor"?new()>
<#assign nowObj2 = objectConstructor("java.util.Date")>
<#assign mmddyy2 = objectConstructor("java.text.SimpleDateFormat","MM/dd/yyyy")>
<#assign now2 = mmddyy2.format(nowObj2)>
example 2: Freemarker print date in template