Forum Discussion

qinglau's avatar
qinglau
Mentor
11 years ago

Control date format output

Hi All, 

 

I would like to display the last login time of users in a date format :

 

 dd-mm-yyyy, like 05-07-2013

 

 I manage to use the REST API call get output : " Dec 12, 2013"

		     <#assign latestLogin = restadmin("/users/id/${user.id}/last_visit_time").value?date("yyyy-MM-dd") />

 

I could not find a way to control output like what I want. I have been look at two disccussion topics here: 

http://community.lithium.com/t5/Developers-Discussion/How-to-format-date-time-output-nicely/m-p/43912#M1224
http://community.lithium.com/t5/Developers-Discussion/REST-API-Date-Format/m-p/51610#M1728

 

 

@xorrkaz , provides some tips in both post. However, i do not know what to do next. :( 

 

Thank you, if you someone knows the answer of that. 

 

Cheers,
Qing

 

 

  • qinglau  That is because you are using a hard coded user ID '17' in the latestLogin and in lastVisit, you are using ${user.id} which is the current user.

     

    use this: 

    <#assign latestLogin = restadmin("/users/id/${user.id}/last_visit_time").value?datetime("yyyy-MM-dd'T'hh:mm:ss")?string("dd-MM-yyyy") />
    ${latestLogin}

     

  • Hi qinglau - Use following:

     

    <#assign lastVisitTime = restadmin("/users/id/[user_id]/last_visit_time")>
    <#assign registrationDateObject = lastVisitTime.value?datetime("yyyy-MM-dd'T'hh:mm:ss") />
    <#assign registrationDateString = registrationDateObject?string("dd/MM/yyyy") />
    ${registrationDateString}

     

  • Or, you can even try this:

     

    <#assign latestLogin = restadmin("/users/id/17/last_visit_time").value?datetime("yyyy-MM-dd'T'hh:mm:ss")?string("dd-MM-yyyy") />
    ${latestLogin}

     

    • qinglau's avatar
      qinglau
      Mentor

      Hi Guys, 

       

      Thank you for the quick reply. I have tried this code 

       

      <#assign latestLogin = restadmin("/users/id/17/last_visit_time").value?datetime("yyyy-MM-dd'T'hh:mm:ss")?string("dd-MM-yyyy") />
      ${latestLogin}
      
      
      

       

      However, the "lastestLogin"output date is not the same as REST call response:

       

       <#assign lastVisit = restadmin("/users/id/${user.id}/last_visit_time/?restapi.response_style=view").value.@view_date />

       

      In REST Call response is 

      <response status="success">
      <value type="date_time" view_date="17-10-2013" view_time="17:47">2013-10-17T15:47:08+00:00</value>
      </response>

       

      The output of lastLogin if i remove the "?string("dd-MM-yyy")" is

      Aug 2, 2011 8:32:02 AM

       

      I guess it must datetime setup format has wrong syntax.  What do u think?

       

      Cheers,
      Qing

       

      • qinglau  That is because you are using a hard coded user ID '17' in the latestLogin and in lastVisit, you are using ${user.id} which is the current user.

         

        use this: 

        <#assign latestLogin = restadmin("/users/id/${user.id}/last_visit_time").value?datetime("yyyy-MM-dd'T'hh:mm:ss")?string("dd-MM-yyyy") />
        ${latestLogin}