I have the following Code that updates my Calendar object.
val date = DatePickerDialog.OnDateSetListener { _, year, monthOfYear, dayOfMonth ->
myCalendar.set(year, monthOfYear, dayOfMonth)
myCalendar.set(Calendar.HOUR, myCalendar.get(Calendar.HOUR))
myCalendar.set(Calendar.MINUTE, myCalendar.get(Calendar.MINUTE))
myCalendar.set(Calendar.SECOND, myCalendar.get(Calendar.SECOND))
updateDate()
}
I receive the following values:
year = 2019
month = 11
day = 31
But when I execute the following code i obtain year = 2020:
private fun updateDate()
{
val myFormat = "dd/MM/YYYY HH:mm:ss"
val sdf = SimpleDateFormat(myFormat, Locale.getDefault())
date_et.setText(sdf.format(myCalendar.time))
}
myCalendar.time
gives me the following string: Tue Dec 31 11:47:00 GMT+01:00 2019
But on date_et
appears the following one: 31/12/2020 11:47:00
Why I have 2019 on Calendar and appears 2020 on my view?
Replace
val myFormat = "dd/MM/YYYY HH:mm:ss"
To
val myFormat = "dd/MM/yyyy HH:mm:ss"