0

I am trying to get a date to look like this format: 23/01/2014

This is what I currently have:

    String testDate = test.getDate();
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    Date convertedDate = new Date();
    try {
        convertedDate = dateFormat.parse(testDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    Log.i("DATE", convertedDate + "");

My output is: Mon Jul 07 09:40:54 GMT 2014 ?

juliet
  • 857
  • 3
  • 10
  • 22
  • 1
    Well, you are parsing a string with the format "dd/MM/yyyy" to a Date object, and not the other way around – Simiil Jul 06 '14 at 21:51
  • `dateFormat.format(Date)` should do the trick – Simiil Jul 06 '14 at 21:53
  • I've also just noticed it doesn't seem to be parsing the date: java.text.ParseException: Unparseable date: "2014-06-01" (at offset 4) – juliet Jul 06 '14 at 22:00
  • then it is printing the current date, because convertedDate is still `new Date()`. Also, `2014-06-01` is obviously not parsable by the pattern `dd/MM/yyyy`, it should be `2014/06/01` – Simiil Jul 06 '14 at 22:02

1 Answers1

0

Try this,

    import android.text.format.DateFormat;
    String dateString = (String) DateFormat.format("dd-MM-yyyy",new java.util.Date());

Check it with a simple toast message.

 Toast.makeText(getActivity(),dateString,Toast.LENGTH_SHORT).show();
SeahawksRdaBest
  • 868
  • 5
  • 17