I have a variable date which is a string that needs to be in this format "yyyy-mm-dd" and i get the data from a variable of type CALENDAR so when the month or the day is less than 10, it only returns the digit "d" or "m". This is the code that i'm doing right now, it's not that good. Is there a better way to do this?
val date: String
if(cal.get(Calendar.MONTH)<9) {
date = cal.get(Calendar.YEAR).toString() + "-0" +
(cal.get(Calendar.MONTH) + 1).toString() + "-" + cal.get(Calendar.DAY_OF_MONTH).toString()
}
else {date = cal.get(Calendar.YEAR).toString() + "-"
+ (cal.get(Calendar.MONTH) + 1).toString() + "-" + cal.get(Calendar.DAY_OF_MONTH).toString()}
Thank you