I'm trying to change the date format I get through an API request. I use GsonBuilser. As I understand it, when changing parameters in setDateFormat (""), the format should change. But with any changes, it gives the result: 2008-01-12T07: 51: 46Z
How do I get a normal date display? Maybe even just dates, without time? Thank! Code below
Gson gsonDate = new GsonBuilder() //.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") .setDateFormat(DateFormat.SHORT, DateFormat.SHORT) .create(); Retrofit retrofitDate = new Retrofit.Builder().baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create(gsonDate)).build(); GitHubUser gitHubUserDate = retrofitDate.create(GitHubUser.class); Call<PojoGitUser> callDate = gitHubUserDate.getUserInfo(login); callDate.enqueue(new Callback<PojoGitUser>() { @Override public void onResponse(Call<PojoGitUser> call, Response<PojoGitUser> response) { PojoGitUser infoDate = response.body(); tvDate.setText("Bio: " + infoDate.getCreatedAt()); } @Override public void onFailure(Call<PojoGitUser> call, Throwable t) { } }); } public interface GitHubUser { @GET("users/{username}") Call<PojoGitUser> getUserInfo(@Path("username") String login); }
infoDate.getCreatedAt()
method? SettingsetDateFormat
affects the conversion of fields of typejava.util.Date, java.sql.Timestamp
andjava.sql.Date
to json and back, but not to display them on the screen. - woesss