How do I convert Date to String ? (Java Language)

Asked

Viewed 75 times

0

public class Passageiro {

    public static void main(String[] args) {

        Viagem passageiro = new Viagem();

        passageiro.nomePassageiro = JOptionPane.showInputDialog("Digite o seu nome:");
        passageiro.dataEmbarque = JOptionPane.showInputDialog("Informe a data da sua viagem:");
        passageiro.destino = JOptionPane.showInputDialog("Informe o seu destino:");

        JOptionPane.showMessageDialog(null, passageiro.exibirReserva());
    }
}
  • 2

    Is there a specific format? Usually just use toString().

  • @bigown Normal format of same dates (day / month / year)

  • It should have other duplicates. Normal format is too wide, which is normal for you is not normal for someone else. Programming is detail.

  • So the exercise doesn’t ask for any specific format, I think it can be anyone’s choice.

  • new SimpleDateFormat("dd/MM/yyyy").format(new Date());

No answers

Browser other questions tagged

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