I am making a post request with the endpoint event/create
@POST("event/create")
Call<EventID> createEvent(@Body CreateEvent createEvent);
In the EventID I am getting a String id. I have get and set methods for it. In the CreateEvent model I am sending String name, nameSecond, title, location and date. I also have get and set methods for them.
In the xml of the activity I have TextInputEditText fields for all of them, but for date and time I have two separate ones, one for date (defined inputType="date"), and one for time (defined inputType="time").
In the Activity i'm getting the text from all of them like this nameEditTxt.getText().toString().trim();
and then I set them like this createEvent.setName(nameEditTxt.getText().toString());
And then I make the call like any other.
The problem I have is with the time and date I need to send them to the server in this format: "2022-05-17T01:43:30.387" and I don't know how to convert them from the user input to match this format. I've tried it like this but it didn't work.
String dateTime = dateEditTxt.getText().toString()+timeEditTxt.getText().toString();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
String result = gson.toJson(dateTime);
System.out.println("Result"+" "+result);
createEvent.setDate(result);
And also in RetrofitBuilder class I added this but I don't know how to use it.
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
.create();