Transfer to "dd/MM/yy" format

Asked

Viewed 100 times

0

I’ve been doing the exercise "6.4 Optional exercises: List of contacts with scriptlet" of Caelum and there is a question that says so : "2) Note that the date appeared in a complicated way to read. Try to show it formatted using the class Simpledateformat"

I need to put this part:

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

But I don’t know where to put it <%=contact getDataNascimen.... , I tried outside 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>
  • Take a look at this post https://answall.com/questions/72828/formata%C3%A7%C3%A3o-de-datas-com-Calendar-dd-mm-yyyy

  • Have you tried that: <%=new SimpleDateFormat("dd/MM/yyyy").format(contato.getDataNascimento())%> ?

1 answer

0

I’m terrible at this language but I think I could do it :

<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>

Years I don’t deal with it ! = P

Browser other questions tagged

You are not signed in. Login or sign up in order to post.