Home Blog Freemarker Browser Issue with Date Formatting

Freemarker Browser Issue with Date Formatting

Poornima
Founder, Femgineer
· November 25, 2009 · 1 min read

When I have to write an internal tool I use Freemarker as my templating engine of choice, because in one file I can write …

When I have to write an internal tool I use Freemarker as my templating engine of choice, because in one file I can write html, and then access Java objects that are passed in a model. Its faster to use for development than engines like Velocity or XMLC, and has enough functionality to write the UI for a tool. The Java objects values are resolved using reflection, to either Strings or Integers.

Recently I ran into a browser compatibility issue. When I used the following code

<#assign currentDate=myObject.todaysDate?date?string.short>

<td>${currentDate}</td>

The dates would render the current date but in the wrong millenium only in Firefox.

The solution is to instead do the following:

<td>${myObject.runDate?date}</td>

The correct date is printed.  The format is month name, date, and year, and it also contains a timestamp.

Enhanced by Zemanta
Pocket
Share on reddit
Share on LinkedIn
Bookmark this on Digg

← Building an Engineering Team - Videos All posts Duke Talk: From Duke to Mint:… →