2016-09-14 58 views
-5

我有一個問題,以改變我得到的迴應DD-MMM-YYYY更改JSON日期格式DD-MMM-YYYY Android中

//json response which i am getting in "mmm-dd-yyyy" 
    String jsondate = map.get("endDate"); 

    Calendar c = Calendar.getInstance(); 

//date format which i need the output 
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy"); 

//the json response which i need to set in "dd-mm-yyyy" 
    viewHolder.end_date.setText(dateFormat.format(c.getTime())); 
+0

顯示您的答案@pappya –

+0

你會得到任何錯誤?你卡在哪裏? – SripadRaj

+0

看看:http://stackoverflow.com/questions/4032967/json-date-to-java-date – 476rick

回答

0
String createdate = 
    new SimpleDateFormat("dd-MM-yyyy").format(
      new SimpleDateFormat("yyyy-MM-dd").parse (yourDate); 
holder.date.setText(createdate); 
+0

謝謝M.Yogeswaran ..... – Gary

+0

如果有用的話,你可以投票答覆 –

0

使用SimpleDateFormat json的日期格式

try { 
      DateFormat originalFormat = new SimpleDateFormat("dd-mm-yyyy", Locale.ENGLISH); 
      DateFormat targetFormat = new SimpleDateFormat("dd-MMM-yyyy"); 
      Date date = originalFormat.parse("21-12-2016"); 
      String formattedDate = targetFormat.format(date); 
     } catch (ParseException e) { 

     }