How to get selected date on calendarView in Long?

Андрей Владиславов :

I have a calendar and want to get selected date to save somewhere. But saving works only if date is in long. When clicking on date, Y, M, D are changing, but view.date isn't. How can I convert D, M, Y to Long or get selected date in long?

Code where I'm trying to get date

sadat :

From year, month, date to Long

    val year = 2020
    val month = 3
    val day = 11
    val calendar = Calendar.getInstance()
    calendar.set(Calendar.YEAR, year)
    calendar.set(Calendar.MONTH, month)
    calendar.set(Calendar.DAY_OF_MONTH, day)
    val longTYpeVariable = calendar.timeInMillis

From Long to year, month abd day

calendar.timeInMillis = longTYpeVariable
val year1 = calendar.get(Calendar.YEAR)
val month1 = calendar.get(Calendar.MONTH)
val day1 = calendar.get(Calendar.DAY_OF_MONTH)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=197086&siteId=1