-2

I am developing an Android application, which has two EditText boxes and a button. In the first EditText box, I set the value 13/08/2014. On pressing the button, the value of the first EditText is converted into Date and then inserted into the second EditText.

I use the following code.

            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
            String ss=todaysdate.getText().toString();
            Date d1 = df.parse(todaysdate.getText().toString());

What happens is, on pressing the button, value of ss and d1 becomes

ss = 13/08/2014
d1 = Thu Jan 08 00:00:00 IST 2015

See the change, it becomes January 8, 2015

Why is this, and what is the error?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Roshan George
  • 187
  • 2
  • 2
  • 13

2 Answers2

0
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = new Date();
String datestring= f.format(date).toString()
David
  • 15,894
  • 22
  • 55
  • 66
emredelioglu
  • 252
  • 1
  • 8
0

Like :-

  String date1 = "15/08/2014";
                Date date3 = new SimpleDateFormat("dd/MM/yyyy")
                        .parse(date1);
                Calendar newCalendar = Calendar.getInstance();
                newCalendar.setTime(date3);
                            SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

                System.out.println(newCalendar.getTime());

                String formatted = format1.format(newCalendar.getTime());
                System.out.println(formatted);
Yogesh Tatwal
  • 2,722
  • 20
  • 43