简体   繁体   English

java.util.Date 到 kotlinx.datetime.LocalDateTime

[英]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.

相关问题 从java.util.Date获取月份号的快速方法 - Fast way to get month number from java.util.Date 如何格式化 kotlinx-datetime LocalDateTime? - How can you format a kotlinx-datetime LocalDateTime? 无法将 1985-04-12T23:20 转换为 java.util.Date - Failed to convert 1985-04-12T23:20 into java.util.Date com.google.firebase.Timestamp 无法在 koltin/android studio 中转换为 java.util.Date - com.google.firebase.Timestamp cannot be cast to java.util.Date in koltin/android studio 发送 GET 请求时无法将“java.lang.String”类型的值转换为所需类型“java.util.Date” - Failed to convert value of type 'java.lang.String' to required type 'java.util.Date' when sending GET request Kotlinx-serialization-json:java.util.NoSuchElementException:列表为空 - Kotlinx-serialization-json: java.util.NoSuchElementException: List is empty java.lang.ClassCastException:kotlinx.coroutines.CompletableDeferredImpl 无法转换为 java.util.List? - java.lang.ClassCastException: kotlinx.coroutines.CompletableDeferredImpl cannot be cast to java.util.List? Kotlin:Java Util Date to String for Databindings - Kotlin: Java Util Date to String for Databindings 是否可以将 kotlinx-datetime 与 Gson 一起使用 - Is it possible to use kotlinx-datetime with Gson 使用 kotlinx.serialization 序列化 Java 路径 - Serializing Java Path with kotlinx.serialization
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM