Convert date dd / mm / yyyy to yyyy-mm-dd'T'HH: mm: ss

7

How do I convert a date in the format dd / mm / yyyy to the format supported by sqlite yyyy-MM-dd'T'HH: mm: ss

Example:

public static String converteStringEmData(String stringData) throws ParseException { 
    SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/aaaa");//yyyy-MM-dd'T'HH:mm:ss
    SimpleDateFormat output = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date data = sdf.parse(stringData);
    String formattedTime = output.format(data);
    return formattedTime;
}
    
asked by anonymous 11.07.2014 / 20:07

1 answer

10

Douglas,

I've had a similar problem converting dates, see if the example below helps address your issue.

  try {
      Log.e(MainActivity.class.getSimpleName(), converteStringEmData("21/03/2014"));
   } catch (ParseException ex) {
      ex.printStackTrace();
   }


public static String converteStringEmData(String stringData) throws ParseException  { 
   SimpleDateFormat simpleDateForma2 = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
   Date receivedDate = simpleDateForma2.parse(stringData);

   String formatedDate = DateFormat.format("yyyy-MM-dd hh:mm:ss", receivedDate).toString();
   return formatedDate;
}

Abs!

    
11.07.2014 / 22:00