How to format date_time output nicely?
- 13 years ago
Hi Claudius,
Messing with dates in FreeMarker can be tricky, but in this case perhaps it's not necessary?
Our REST API supports a parameter called restapi.response_style that when set to view, will provide additional details in the response such as UI-style URLs, as well as UI-style dates and times. Here's a sample call:
/restapi/vc/threads/recent?restapi.response_style=view
If you look at a time or date in the response, you'll notice the element now has some additional attributes:
<post_time type="date_time" view_date="04-17-2012" view_time="01:44 AM" view_friendly_date="11 hours ago">2012-04-17T08:44:31+00:00</post_time>
So now you have the nicer version of the time and date in the response, and you'll notice that it even includes the friendly (relative) date version if you have that enabled for your community. The nice thing about this, is that it also respects the time zone preferences of the user. When you use the rest context object in a custom component, this parameter is already included for you, so you can take advantage of it without any further action.
Then to access these attributes, you can do this:
${message.post_time.@view_date} ${message.post_time.@view_time} ${message.post_time.@view_friendly_date}
If this doesn't help, let me know and I can try to help you work through the Freemarker.
Regards,
Adam