How to serialize a data type date, with retrofit?

-1

Good day.

I have an Android form in which in one of the fields I select a date, this data is sent by the method POST , for this I am using retrofit , but this date I must serialize it or convert it to this format:

  

yyyy-MM-dd'T'HH: mm: ss

.

The Post method is like this:

@FormUrlEncoded
@POST("api/books/{bid}/books")
Call<Book> postBook(@Path("bid") String bookId,
@Field("bookRequest[additionalComment]") 
String additionalComment,
@Field("bookRequest[contactPhone]") String contactPhone, 
@Field("bookRequest[suggestedDate]") String date);

How could I solve this situation? Thank you in advance.

    
asked by devjav 15.12.2016 в 16:44
source

1 answer

0

It has nothing to do with Retrofit, but you can use this:

public static String getCurrentISODate() {
    TimeZone tz = TimeZone.getTimeZone("UTC");
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault()); // La "Z" indica UTC, sin offset de zona
    df.setTimeZone(tz);
    return df.format(new Date());
}
    
answered by 15.12.2016 в 16:49