简体   繁体   中英

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?

我试图获取日期的代码

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM