2
I’m having trouble formatting a date for useful, I need to format a date that this Tue Nov 22 00:00:00 BRST 2017 (example) for date in format dd/MM/yyyy
.
I’ve been seeing some links, like: How to convert a string to date? but it’s not working, I believe I don’t know how to use - los.
Date data = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(data);
//eu ultilizo o calendar em alguns calculos, depois eu seto ele no meu pojo.
//porém ele vem nesse formato, exemplo: Tue Nov 22 00:00:00 BRST 2017
//quero converter em dd/MM/yyyy
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
meuPojo.setVencimento(sdf.parse(calendar.getTime())); // minha tentativa de converter, porém da erro de: "incompatible types: Date cannot be converted to String"
//exemplo de como é o meu método setVencimento
public void setVencimento(Date data){
this.data = data;
}
If the
setVencimento
gets aDate
just passcalendar.getTime()
for that is already aDate
no need to parse. Can’t parse aDate
which is what you’re trying to do– Isac
A detail, when you do
new Date()
, is creating aDate
corresponding to the current date/time. And when callingCalendar.getInstance()
, is creating aCalendar
corresponding to the current date/time. Then create theDate
and then move on toCalendar
withsetTime
is redundant and unnecessary (it would only make sense if theDate
did not correspond to the current date/time).– hkotsubo