我想将日期从String转换为Long并插入数据库空间。为此,我尝试使用TypeConverters。
open class DateStringLongConverter {
private val DATE_PATTERN = "dd.MM.yyyy"
@TypeConverter
fun stringToLong(string: String): Long {
UIDateUtils.getDayBeginTime()
val form = SimpleDateFormat(DATE_PATTERN, Locale.getDefault())
return form.parse(string).time
}
@TypeConverter
fun longToString(long: Long): String {
val form = SimpleDateFormat(DATE_PATTERN, Locale.getDefault())
return form.format(long)
}
}
但日期未转换。这是我的实体
@TypeConverters(StringListConverter::class)
class WaybillEntity(
@PrimaryKey(autoGenerate = false)
val id: Int? = null,
@ColumnInfo(name = "idWaybill")
val idWaybill: Int,
val number: String,
@TypeConverters(DateStringLongConverter::class)
val date: String
)