For Kotlin
fun Calendar.getFullDate(): String { val mYear = "${this.get(Calendar.YEAR)}-" val mMonth = if (this.get(Calendar.MONTH) + 1 < 10) {"0${this.get(Calendar.MONTH) + 1}-" } else {"${this.get(Calendar.MONTH)+ 1}-" } val mDate = if (this.get(Calendar.DAY_OF_MONTH) < 10) {"0${this.get(Calendar.DAY_OF_MONTH)}" } else {"${this.get(Calendar.DAY_OF_MONTH)}" } return mYear + mMonth + mDate}
and use it as
val date: String = calendar.getFullDate()