Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.time.LocalDateTime
- import java.time.temporal.ChronoUnit
- fun main(args : Array<String>) {
- // 2019-05-24 14:17:00 | 2019-09-13 14:15:51
- val start = "2019-05-24 14:17:00"
- val end = "2019-09-13 14:15:51"
- daysBetweenDates(start, end)
- }
- fun daysBetweenDates(start: String, end: String) {
- val mStart = LocalDateTime.parse(start)
- val mEnd = LocalDateTime.parse(end)
- val difference = ChronoUnit.DAYS.between(mStart, mEnd)
- println("START => $mStart")
- println("END => $mEnd")
- println("DIFFERENCE => $difference days")
- }
- Exception in thread "main" java.time.format.DateTimeParseException: Text '2019-05-24 14:17:00' could not be parsed at index 10
- at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
- at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
- at java.time.LocalDateTime.parse(LocalDateTime.java:492)
- at java.time.LocalDateTime.parse(LocalDateTime.java:477)
- at MainKt.daysBetweenDates(main.kt:16)
- at MainKt.main(main.kt:11)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement