Transforms in "dd / MM / yy" format

0

I've been doing the exercise 6.4 Optional exercises: Caelum's list of contacts with scriptlet and there's a question that says: " 2) Notice that the date appeared in a complicated way Try formatting it using the class SimpleDateFormat "

I need this section:

String dataFormatada = new SimpleDateFormat("dd/MM/yyyy").format(contato.getDataNascimento())

But I do not know where to put it already I've tried replacing the <% = contact.getDataNascimen .... , already tried off the table and nothing ..

This is my code!

<table>
<tr>
<th>Nome</th>
<th>E-mail</th>
<th>Endereço</th>
<th>Data de Nascimento</th>
</tr>
<%
ContatoDao dao = new ContatoDao();
List<Contato> contatos = dao.getLista();

for (Contato contato : contatos){
%>
<tr>
    <td><%=contato.getNome() %></td>
    <td><%=contato.getEmail() %></td>
    <td><%=contato.getEndereco() %></td>
    <td><%=contato.getDataNascimento().getTime() %></td>
</tr>
<%
}
%>
</table>
    
asked by anonymous 04.07.2017 / 04:45

1 answer

0

I'm terrible at this language but I think I could do that:

<table>
    <tr>
        <th>Nome</th>
        <th>E-mail</th>
        <th>Endereço</th>
        <th>Data de Nascimento</th>
    </tr>
    <%
     ContatoDao dao = new ContatoDao();
     List<Contato> contatos = dao.getLista();
     for (Contato contato : contatos){
   %>
    <tr>
    <td><%=contato.getNome() %></td>
    <td><%=contato.getEmail() %></td>
    <td><%=contato.getEndereco() %></td>
       <%  
         String dataFormatada = new 
         SimpleDateFormat("dd/MM/yyyy").format(contato.getDataNascimento());%>
    <td><%= dataFormatada   %></td>
  </tr>
  <%
   }
  %>
 </table>

I do not care about that! = P

    
04.07.2017 / 04:52