Search code examples
androiddatepickerretrofitretrofit2android-datepicker

datepicker value from edittext using Retrofit post request


im using retrofit post request method to post date from edittext(date retrieved from datepicker)...when i select date from datepicker and select date on it..it is displaying right date on edittext...but when i submit and check on postman it is showing wrong date..

need help thanks

following is my code:

 val myCalendar: Calendar = Calendar.getInstance()

    val edittext1 = findViewById(R.id.dob) as EditText
    val date =
        OnDateSetListener { view, year, monthOfYear, dayOfMonth -> // TODO Auto-generated method stub
            myCalendar.set(Calendar.YEAR, year)
            myCalendar.set(Calendar.MONTH, monthOfYear)
            myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth)
            val myFormat = "dd-MM-yyyy" //In which you need put here
            val sdf = SimpleDateFormat(myFormat, Locale.US)
            edittext1.setText(sdf.format(myCalendar.getTime()))      }

    edittext1.setOnClickListener(object : View.OnClickListener {
        override fun onClick(v: View?) {
            // TODO Auto-generated method stub
            DatePickerDialog(
                this@EditProfile, date, myCalendar
                    .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
                myCalendar.get(Calendar.DAY_OF_MONTH)
            ).show()
        }
    })

here is my posting on retrofit:im not displaying full code just to understand im posting it:

//here im posting ediitext.tostring
RetrofitClient.instance.useredit(token,first_name,last_name,email,edittext1.toString(),phone,profile)
            .enqueue(object : Callback<LoginResponse> {
                override fun onFailure(call: Call<LoginResponse>, t:.................................

postman output:-if i select todays date and posting...it is showing always one date --> 01-01-1970 in postman


Solution

  • You should use edittext1.getText() instead of edittext1.toString().