0

I've a array list object in which one of the date time field is 2014-06-13 19:05:00, after converting the list object to json object using Google gson it changes to Jun 13, 2014 7:05:00 PM. I don't want it to convert on its own. Any ideas?

Gson objGson = new Gson();

String messages = objGson.toJson(listMessages);
Nizam Ali
  • 241
  • 2
  • 9
  • 16

2 Answers2

3

You can try with GsonBuilder#setDateFormat()

Gson gson = new GsonBuilder()
                   .setDateFormat("yyyy-MM-dd HH:mm:ss").create();

For more info have a look at GSON - Date format

If nothing works then try with Custom Serialization and Deserialization

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
0

You need to format when you extract date from json. Alternate solution is: Add your date to json as strings and get them as strings.

Darshan Lila
  • 5,772
  • 2
  • 24
  • 34