Incorrect date/time format

Asked

Viewed 73 times

1

In my next code snippet:

String horario = evento.getDataOcorrencia().concat(" ").concat(evento.getHoraOcorrencia());
                    horario = horario.replaceAll("/", "-");
                    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy hh:mm");
                    Date parsedDate = dateFormat.parse(horario);
                    Timestamp timestamp = new Timestamp(parsedDate.getTime());
                    evento.setHorario(timestamp);

My String time has the following format (example):

28/03/2017 10:00

I need to convert to a timestamp, so far so good, I even change the / for -. The problem is that when the value is persisted in the bank:

2017-03-21 13:35:00

That is, it is a format that I would not like, I wanted it to be as it is in the example. Does anyone know how I can solve ? The JPA is like this:

@Column
@XmlTransient
private Timestamp horario;
  • Let the bank persist as you wish. Worry about the display only at the time of display. By the way, the database is following the ISO standard to display a date. Internally, it must be holding an integer number of many bytes. Possibly with the amount of seconds the milliseconds after epoch

  • Not even to show on screen I’m getting, how can I do ?

  • Are you using SimpleDateFormat or something worth it? Or is it just in the toString?

  • Simpledateformat

  • So it’s not just a matter of taking the "2017-03-21 13:35:00" string obtained from the database and turning it into a "03/28/2017 10:00" string to display the latter in the GUI?

No answers

Browser other questions tagged

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