I want to use an array of data class
where one of the parameters is Date
, I could not use Date() as it looks to be related to KotlinJS
, so I tried using LocalDate
so I wrote the below code:
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.*
data class transaction (var date: LocalDate, var quantity: Double)
val formatter: DateTimeFormatter
get() = DateTimeFormatter.ofPattern("dd.mm.yyyy", Locale.ENGLISH)
fun main(args: Array<String>) {
var salesOrders = ArrayList<transaction>()
println("Hello, world! ")
salesOrders.set(0, transaction(LocalDate.parse("01.02.2018", formatter), 0.0))
println(salesOrders)
}
But, as shown at tryKotlin I’m getting an error, that:
Text ‘01.02.2018’ could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {Year=2018, MinuteOfHour=2, DayOfMonth=1}.