Hi, I need some help with date conversion. I have ...
# exposed
f
Hi, I need some help with date conversion. I have a datetime in MySql and I want to read it with my API made in exposed. The Table has a column as follows:
Copy code
val endTime = datetime("end_time")
and the data class has
Copy code
val endTime: LocalDateTime?
in my DAOFacadeImpl class I perform the mapping between row and object as follows:
Copy code
endTime = row[Events.endTime].toString().toLocalDateTime(),
but I have the following exception:
Copy code
kotlinx.datetime.DateTimeFormatException: java.time.format.DateTimeParseException: Text '2014-01-26T17:30:00.000+01:00' could not be parsed, unparsed text found at index 23
I'm using kotlinx.datetime because it supports the object Serialization. I suppose that the date read from database is not in ISO format (in the database I do not have the +01:00), but how to change its format to be an ISO format? Any suggestion about? thanks all
t
datetime
column from exposed-kotlin-datetime already has
LocalDateTime
type. What column type is in your database?
f
@tapac the column type in MySql database is datetime
I've solved as follows:
Copy code
row[Events.endTime].toString().toInstant().toLocalDateTime(TimeZone.currentSystemDefault())
datetime
type for column
endTime
depends on
org.jetbrains.exposed.sql.jodatime
632 Views