In Application, i am using Retrofit
to consume api data. As converter i am using Gson
new GsonBuilder()
.setDateFormat("yyyy-MM-dd")
.create();
I am getting Date
types like below from api. But i cannot convert it to java.util.Date
object.
{
"date":{
"year":2018,
"month":2,
"day":11
},
"time":{
"hour":22,
"minute":40,
"second":0,
"nano":0
}
}
To get this type of date i create new classes named CustomDate, CustomTime, CustomDateTime.
CustomDate
public class CustomDate implements Serializable{
private int year;
private int month;
private int day;
CustomTime
public class CustomTime implements Serializable {
private int hour;
private int minute;
private int second;
private int nano;
CustomDateTime
public class CustomDateTime implements Serializable {
private CustomDate date;
private CustomTime time;
My question is how can i convert consumed data without above custom classes.What i actually want is dateformatter. What should i put .setDateFormat("")
to handle date conversion.