The java.util.Date
class has a method called toInstant()
that converts the Date
instance to a java.time.Instant
.
The java.sql.Date
class extends the java.util.Date
class, but when I attempt to call toInstant()
on a java.sql.Date
, I receive an UnsupportedOperationException
。
为什么 toInstant()
在 java.sql.Date
上不受支持的操作?
将 java.sql.Date
java.time.Instant
“正确”方法是什么?
原文由 Andrew Mairose 发布,翻译遵循 CC BY-SA 4.0 许可协议
根据 JavaDoc
由于
sql.Date
没有时间分量,因此无法将其转换为time.Instant