1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| @RequiresApi(Build.VERSION_CODES.O) fun main() { val start = "2021-05-20 00:00:00" val end = "2021-05-20 24:00:00" secondBetweenDates(start, end) }
@RequiresApi(Build.VERSION_CODES.O) fun secondBetweenDates(start: String, end: String) { val mStart = LocalDateTime.parse(start, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) val mEnd = LocalDateTime.parse(end, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) val difference = ChronoUnit.SECONDS.between(mStart, mEnd) println("START => $mStart") println("END => $mEnd") println("DIFFERENCE => $difference Second") }
|