Technical Leader’s Playbook is now enrolling. Limited spots · closes May 29 Learn more →
Software Development

Freemarker Browser Issue with Date Formatting

· · 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 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

Poornima

Founding engineer at Mint.com. Senior SWE & EPM at Apple. Building communication systems for technical professionals.

The Femgineer Newsletter

Technical communication, delivered weekly.