Forum Discussion

janh's avatar
janh
Mentor
12 years ago

Rest API call for Date to show user selected Date Format

Hi there,

 

Currently we use the following code to pull the date from a post and then display at a particular date format, 'MM/dd/yyyy':

<#assign date = message.post_time?datetime("yyyy-MM-dd'T'HH:mm:ss'+00:00'") />      

${date?string("MM/dd/yyyy")} ${message.post_time.@view_time}

 

The output would look like as follows: 02/27/2012 05:59 PM , which works well enough but I noticed that users can select their own format like dd-MM-yyyy or yyyy-MM-dd.

 

Does anyone know if there is a way to get the date format selected by the user in their settings so the code can display the date as per their format setting?

 

Cheers

  • JuergenH's avatar
    JuergenH
    Lithium Alumni (Retired)

    Hey Jan,

     

    have you checked the API documentation

     

    According to the documentation, the view_date parameter will only return the format of the registered user submitting the call - so this will only work if you have access to the user account. I did not find any solution to get the format for any registered user unfortunately.

     

    If a request specifies the parameter restapi.response_style with the value view, the response will include attributes that relate the elements to the standard web interface. The attributes include

    AttributeDescription
    view_href For elements that are associated with a page in the standard web interface, this specifies the URL for that page.
    view_date Included in date/time elements. This provides a date string formatted as expected by the Lithium user associated with the call.
    view_time Included in date/time elements. This provides a time string formatted as expected by the Lithium user associated with the call.