0

I have problem with date picker. When i select date. I would like to parse it to format d/m/yy. Unfortunatelly it doestn works correctly.
String returned is like

7/67/89

 private SimpleDateFormat sdf = new SimpleDateFormat("d/m/yy");
public void openDataPicker(View view) {
    clickedTextEdit = (TextInputEditText) view;
    final Calendar cldr = Calendar.getInstance();
    int day = cldr.get(Calendar.DAY_OF_MONTH);
    int month = cldr.get(Calendar.MONTH);
    int year = cldr.get(Calendar.YEAR);

    picker = new DatePickerDialog(CreateProfileActivity.this,
            new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    Calendar c = Calendar.getInstance();
                    c.set(year, monthOfYear, dayOfMonth);
                    clickedTextEdit.setText(sdf.format(c.getTime()));
                }
            }, year, month, day);
    picker.show();
}
Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
VANILKA
  • 634
  • 1
  • 13
  • 32
  • Tip: try to find more relevant tags for your problem to attract more people who know about it (I added a couple). – Ole V.V. Jun 28 '19 at 19:16

2 Answers2

2

Use the correct format.

See this:


"EEE, d MMM yyyy HH:mm:ss Z"   // Wed, 4 Jul 2001 12:08:56 -0700
"yyMMddHHmmssZ"                // 010704120856-0700
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" // 2001-07-04T12:08:56.235-0700
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX" // 2001-07-04T12:08:56.235-07:00
"YYYY-'W'ww-u"                 // 2001-W27-3
"yyyy.MM.dd G 'at' HH:mm:ss z" // 2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy"             // Wed, Jul 4, '01
"h:mm a"                       // 12:08 PM
"hh 'o''clock' a, zzzz"        // 12 o'clock PM, Pacific Daylight Time
"K:mm a, z"                    // 0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa" // 02001.July.04 AD 12:08 PM``
Anupam
  • 2,845
  • 2
  • 16
  • 30
1

Your Format "d/m/yy" in SimpleDateFormat means:

d = the date of the month

m = minute, NOT MONTH

yy = Year

the format you need is dd/MM/yy

More formats you can see here on Android SimpleDateFormat Page.

Community
  • 1
  • 1
Deˣ
  • 4,191
  • 15
  • 24