title: Formatting Date in DatePicker, Storing Date in Database
body: <p>I am fetching a Date from a <code>DatePicker</code> which formats it depending on the user location (I think). I would like to format this Date so the user can choose a format.</p>
  
  <p>Also I want to store this date to a Database. For later usage I'd like to use the format <code>yyyyMMdd</code>. </p>
  
  <p>My problem right now is still with  the <code>DatePicker</code> formatting my Date.</p>
  
  <p>This is what I have written right now:</p>
  
  <pre><code> public static class DatePickerFragment extends DialogFragment implements
              DatePickerDialog.OnDateSetListener, OnClickListener {
  
  
          @Override
          public Dialog onCreateDialog(Bundle savedInstanceState) {
              // Use the current date as the default date in the picker
  
  
              final Calendar c = Calendar.getInstance();
              int year = c.get(Calendar.YEAR);
              int month = c.get(Calendar.MONTH);
              int day = c.get(Calendar.DAY_OF_MONTH);
  
              return new DatePickerDialog(getActivity(), this, year, month, day);
  
          }
  
          public void onDateSet(DatePicker view, int year, int month, int day) {
  
  
              // Do something with the date chosen by the user
  
                  dateValue = String.valueOf("" + day + "." + (month + 1) + "." + year);
                  date_widget.setText(dateValue);
  
  
  
              try {
                  SimpleDateFormat sdfToDate = new SimpleDateFormat(
                          "yyyyMdd");
  
                  dateDB = String.valueOf(sdfToDate.parse(dateValue));
                  Log.e("Date", dateDB);
              } catch (ParseException ex2) {
                  ex2.printStackTrace();
  
              }
  
  
  
  
  
          }
  
          @Override
          public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub
          }
      }
  </code></pre>
  
  <p>I don't think this is the best way to do this but the <code>DatePicker</code> works.</p>
  
  <p>Since my month has only 1 digit i get an exception when trying to format my dateValue:</p>
  
  <pre><code> Unparseable date: "22.6.2013" (at offset 7)
  </code></pre>