Last active
July 31, 2019 13:02
-
-
Save reuniware/fb6ca47a286639dfdab6d385236b1d8d to your computer and use it in GitHub Desktop.
Android Kotlin Calendar get 1st day of year and last day of year
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// first day of year | |
val cal = Calendar.getInstance() | |
cal.set(Calendar.MONTH, 0) | |
cal.set(Calendar.DAY_OF_MONTH, 1) | |
val year_start = cal.get(Calendar.YEAR) | |
val month_start = cal.get(Calendar.MONTH) // Mois de 0 à 11 | |
val day_start = cal.get(Calendar.DAY_OF_MONTH) | |
textViewStartDate.setText("${String.format("%02d", day_start)}/${String.format("%02d", month_start+1)}/${String.format("%04d", year_start)}") | |
// last day of year | |
cal.set(Calendar.MONTH, 11) | |
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)) | |
val year_end = cal.get(Calendar.YEAR) | |
val month_end = cal.get(Calendar.MONTH) // Mois de 0 à 11 | |
val day_end = cal.get(Calendar.DAY_OF_MONTH) | |
textViewEndDate.setText("${String.format("%02d", day_end)}/${String.format("%02d", month_end+1)}/${String.format("%04d", year_end)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment