berkoberkonew
berkoberkonew

Reputation: 87

How to get a date from a JSON

I pull the date from the mysql database. When shooting this date, the output is as follows:

"form_tarih2":{"date":"2019-11-27 14:42:23.000000","timezone_type":3,"timezone":"UTC"}}

I pull form_tarih2 in my application but I cannot show the date data. How can I just pull the date data?

 try {
            JSONObject jObj = new JSONObject(result);
            String tarihstring = jObj.getString("form_tarih2");
}

Upvotes: 1

Views: 68

Answers (2)

TIenHT
TIenHT

Reputation: 91

Because form_tarih2 is a node, so maybe this code below will help you:

JSONObject jObj = new JSONObject(result);
JSONObject form_tarih2 = jObj.getJSONObject("form_tarih2");
String date = form_tarih2.getString("date");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date birthDate = sdf.parse(date);

Upvotes: 1

Vishal
Vishal

Reputation: 184

You can use GSON library provided by Google or as below,

  try{
        JSONObject jObj = new JSONObject(result);
        String tarihstring = jObj.getString("form_tarih2");
        JSONObject testObject = new JSONObject(tarihstring);
        String date = testObject.getString("date");

 }catch(Exception e)
 {

 }

Upvotes: 1

Related Questions