Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import java.time.LocalDateTime
  2. import java.time.temporal.ChronoUnit
  3.  
  4. fun main(args : Array<String>) {
  5.  
  6. // 2019-05-24 14:17:00 | 2019-09-13 14:15:51
  7. val start = "2019-05-24 14:17:00"
  8. val end = "2019-09-13 14:15:51"
  9.  
  10. daysBetweenDates(start, end)
  11. }
  12.  
  13.  
  14. fun daysBetweenDates(start: String, end: String) {
  15. val mStart = LocalDateTime.parse(start)
  16. val mEnd = LocalDateTime.parse(end)
  17.  
  18. val difference = ChronoUnit.DAYS.between(mStart, mEnd)
  19. println("START => $mStart")
  20. println("END => $mEnd")
  21. println("DIFFERENCE => $difference days")
  22. }
  23.  
  24. Exception in thread "main" java.time.format.DateTimeParseException: Text '2019-05-24 14:17:00' could not be parsed at index 10
  25. at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
  26. at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
  27. at java.time.LocalDateTime.parse(LocalDateTime.java:492)
  28. at java.time.LocalDateTime.parse(LocalDateTime.java:477)
  29. at MainKt.daysBetweenDates(main.kt:16)
  30. at MainKt.main(main.kt:11)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement