[英]java.util.Date to kotlinx.datetime.LocalDateTime
I have a value of type java.util.Date
which was obtained from a legacy third-party API. Is there a direct way of converting it to kotlinx.datetime.LocalDateTime
?我有一个类型为
java.util.Date
的值,它是从遗留第三方 API 获得的。是否有直接的方法将其转换为kotlinx.datetime.LocalDateTime
? I know how to do it only in a roundabout way, such as serializing to String and deserializing, or by converting to java.time.LocalDateTime
first and then to the wanted type.我只知道如何以迂回的方式做到这一点,例如序列化为 String 并反序列化,或者先转换为
java.time.LocalDateTime
,然后再转换为所需的类型。
i Think the best thing you can do is to convert it to a string and than convert into a kotlinx.datetime.LocalDateTime
我认为你能做的最好的事情就是把它转换成一个字符串,而不是转换成一个
kotlinx.datetime.LocalDateTime
The problem is that not all java types can be converted directly into a kotlin one especially not with the old DataType java.util.Date.
问题是并非所有 java 类型都可以直接转换为 kotlin 类型,尤其是旧数据类型
java.util.Date.
It is also posible with the new DataType java.time.LocalDateTime
.它也适用于新的数据类型
java.time.LocalDateTime
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.