Issue
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
.
Why is toInstant()
an unsupported operation on java.sql.Date
?
And what is the "correct" way to convert a java.sql.Date
to a java.time.Instant
?
Solution
According to the JavaDoc
Since sql.Date
does not have a time component, there is no possibility to convert it to time.Instant
This method always throws an UnsupportedOperationException and should not be used because SQL Date values do not have a time component.
Answered By - Yassin Hajaj