6
I’m trying to return a date that is recorded right in the bank (1986-04-30 17:02:00), I try to convert this date to appear only "30/04/1986", but no use.
The most I can get back is Wed Apr 30 00:00:00 BRT 1986.
I’m creating the list with Hibernate.
public List<Fornecedor> listarFornecedores() {
session = HibernateUtil.getSessionFactory().openSession();
List<Fornecedor> listaFornecedores = new ArrayList<Fornecedor>();
query = session.createQuery("FROM Fornecedor");
listaFornecedores = query.list();
session.close();
return listaFornecedores;
}
and at Get of the Suppliers Class I tried everything, but I get to that point without error:
public Date getInicioAtividades() throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String data = sdf.format(inicioAtividades);
Date dataI = sdf.parse(data);
return dataI;
}
If it were to return a string, all legal, with the SimpleDataFormat
gets it right, though, I’d like to return a Date. Someone can give me a strength?
I think this is not possible, since in a Date always returns the full timestamp information. I think only via string same. See this answer on Soen
– user28595
What is the type of activities and how you populate it?
– Marcus Martins
This way you only get as String. What you can do is to have two get’s, one that returns Date and the other that returns String. Ex: public Date getInitionActivities() { Return Homeactivities} public String getInitiesFormated() { //Your logic with Simpledateformat}
– Hugo Lima
Thanks Hugo! I think this way it will work.
– sounobre
But how would I do that Hugo.... Now that I stopped to think, I ended up getting confused...
– sounobre
When I do the search, it will return the getInicioAtivities... how do I search get the getInicioAtivitiesFormated?
– sounobre
Put the error there, that if it is a code problem, it is easier to solve Can you do yes, in the saved String bank? if yes... then you need to make a convert to Hibernate there meets you. , if it is already in date form, then there is no problem, only when it is to show use your method, if it is saved in the database for String and has the permission to fix, do this change to date
– Marcelo Ferreira
The idea they gave was to do the following, create the following method: public String getInicioFormated() throws Parseexception { Simpledateformat sdf = new Simpledateformat("dd/MM/yyyy"); String data = sdf.format(startAtivities); Return data; } but how do I get this Kra? how do I get the feedback? is to insert in the class.java right? sorry for the silly questions... but I’m beginner...rs
– sounobre