Date formatting using #dates.format

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Date formatting using #dates.format

benr
I can get this to work:
<span th:text="'Added by ' + ${bean.addedBy} + ' on ' + ${#dates.format(bean.addedOn, 'd MMMM yyyy H:mm')}">Added by X on 12 July 2006 9:53</span>
but not this:
<span th:text="'Added by ' + ${bean.addedBy} + ' on ' + ${#dates.format(bean.addedOn, 'd MMMM yyyy \'at\' H:mm')}">Added by X on 12 July 2006 at 9:53</span>
How do I escape the value "at" in the date pattern if I'm already using both the single and double quotes in the surrounding text? Java's SimpleDateFormat allows:
String format = "d MMMM yyyy 'at' H:mm";
Cheers, Ben
Reply | Threaded
Open this post in threaded view
|

Re: Date formatting using #dates.format

Emanuel
Administrator
Looking at the stack trace of the error that occurs when you do this, it looks like it's a SpEL issue.  Googling for how to escape single-quotes in SpEL showed me that you should put 2 single-quotes together to escape it, so you'll end up with:

${#dates.format(bean.addedOn, 'd MMMM yyyy ''at'' H:mm')}