iex
04/07/2020, 11:28 AMjava.text.SimpleDateFormat
fail if the date string doesn't match exactly? Tried setting isLenient
to false but it didn't work. Specifically I want that if the format is "yyyy-MM-dd", e.g. "2019-08-05T235959+0200" is NOT parsed. it should only parse if the date string is "2019-08-05"
val str = "2019-08-05T23:59:59+0200"
val format = SimpleDateFormat("yyyy-MM-dd")
format.isLenient = false
format.parse(str) // should return null or crash
df
04/07/2020, 11:41 AMdiesieben07
04/07/2020, 11:41 AMDateTimeFormatter
from java.time
?SimpleDateFormat
you can use ParsePosition
to detect extraneous text at the end:
val position = ParsePosition(0)
val input = "2019-08-05T23:59:59+0200"
val parsed = format.parse(input, position)
if (position.index != input.length) {
throw Exception("Invalid Date")
}
iex
04/07/2020, 2:09 PMjava.time
because I'm using the Android SDKLocalDate.parse()
? Haven't seen thisdiesieben07
04/07/2020, 2:09 PMLocalDate
is also part of java.time
.iex
04/07/2020, 2:10 PMParsePosition
seems usable 👍LocalDate
eitherdiesieben07
04/07/2020, 2:10 PMjava.time
Time apis like the plagueiex
04/08/2020, 9:52 PM