OK so you're trying to format a String. That is, temp
is a String and you can't pass that into format
. You need to turn that String into a Date then pass it into format
. Here's how.
But, even better, you should be returning a Date
from the query instead of a String
. That'll make your life much easier. Then you don't need to change any other part of the code.
Show us your connectToDB
. Assuming it's using JDBC, you should get the result by calling ResultSet.getDate