0

I am trying to convert date..........

String date = null ;
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.000'+'0530");
            date = Utils.getDateBasedOnCurrentDate(mPosition);
            Date attendancedate = dateFormat.parse(date);
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            date = format.format(attendancedate);
            Log.e("ddddddddddddddddddd", date);
        }catch (ParseException e){
            e.printStackTrace();
        }

but it gives exception :

java.text.ParseException: Unparseable date: "2016-05-17T18:52:54.078+0530" (at offset 21)

Bhoomika Brahmbhatt
  • 7,404
  • 3
  • 29
  • 44

2 Answers2

0

Change this line with

 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.000'+'0530");

this

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
0

try this answer:

SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date now = new Date();

       // String inputPattern = "EEE MMM d HH:mm:ss zzz yyyy";

        String outputPattern = "dd-MM-yyyy";

        //SimpleDateFormat inputFormat = new SimpleDateFormat(inputPattern);
        SimpleDateFormat outputFormat = new SimpleDateFormat(outputPattern);

        //Date date = null;
        String str = null;

        try {
            String time = sdfDate.format(now);
            //date = inputFormat.parse(time);
            str = outputFormat.format(now);
            Log.i("mini1", "Converted Date Today:" + time);
            Log.i("mini", "Converted Date Today:" + str);
           // Toast.makeText(getApplicationContext(), str, 5000).show();
        } catch (ParseException e) {
            e.printStackTrace();
        }
Damini Mehra
  • 3,257
  • 3
  • 13
  • 24