java - How to pass a model property to a javascript function in JSP which itself returns a value -


i have format date have received controller [spring] in jsp page itself.
here's jsp file :

<%@ page language="java" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>  <!doctype html> <html lang="en">  <head>  <script src="${pagecontext.request.contextpath}/static/js/custom/customer.js">/script> </head> <body>                  <table id="success-story">                     <thead>                         <tr>                             <th width="5%">sl#</th>                             <th width="50%">description</th>                             <th width="10%">status</th>                             <th width="30%">created on</th>                             <th width="5%">actions</th>                         </tr>                     </thead>                     <tbody>                         <c:foreach items="${customer.rfqs}" var="v" varstatus="count">                             <tr>                                 <td>${count.count}</td>                                 <td>${v.description}</td>                                 <td>${v.status}</td>                                 <td>$v.createdts</td>                                 <td align="center">                                    <a href="#" onclick="view(${v.requestid})"> view</a>                                    <a href="#" onclick="edit(${v.requestid})">edit</a>                                 </td>                             </tr>                         </c:foreach>                     </tbody>                 </table>    </body>  </html>' 

the ${v.createdts} returns timestamp of form yyyy:mm:dd hh:mm:ss
have convert timestamp format dd:mm:yyyy
done @ frond end while populating row, how can done ?

have tried many possible solutions none of them worked, here's function have in js file

customer.js :

function formatdate(date) {   var monthnames = [     "jan", "feb", "mar",     "apr", "may", "jun", "jul",     "aug", "sep", "oct",     "nov", "dec"   ];    var day = date.getdate();   var monthindex = date.getmonth();   var year = date.getfullyear();    return day + ' ' + monthnames[monthindex] + ' ' + year; } 

can use function in way or other alternative work me. need conversion.
advance thanks

if createdts property date object - can use fmt tag.

<fmt:formatdate pattern = "yyyy-mm-dd" value = "${v.createdts}" /> 

if of string type, may formating @ server side.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -